From 65d7e517afa8e43a9a9b95aae6528a62c932fe2a Mon Sep 17 00:00:00 2001 From: Dual Tachyon Date: Sat, 16 Sep 2023 00:27:18 +0100 Subject: [PATCH] Fixed and documented PORTCON configuration. --- Makefile | 4 + board.c | 251 ++++++++++++++++++++++++++++++++++++++++++++----------- 2 files changed, 206 insertions(+), 49 deletions(-) diff --git a/Makefile b/Makefile index a8fc1785..70189139 100755 --- a/Makefile +++ b/Makefile @@ -4,6 +4,7 @@ ENABLE_AIRCOPY := 1 ENABLE_FMRADIO := 1 ENABLE_NOAA := 1 ENABLE_OVERLAY := 1 +ENABLE_SWD := 0 ENABLE_UART := 1 BSP_DEFINITIONS := $(wildcard hardware/*/*.def) @@ -131,6 +132,9 @@ endif ifeq ($(ENABLE_OVERLAY),1) CFLAGS += -DENABLE_OVERLAY endif +ifeq ($(ENABLE_SWD),1) +CFLAGS += -DENABLE_SWD +endif ifeq ($(ENABLE_UART),1) CFLAGS += -DENABLE_UART endif diff --git a/board.c b/board.c index dce967cb..390a9503 100644 --- a/board.c +++ b/board.c @@ -59,32 +59,53 @@ void BOARD_FLASH_Init(void) void BOARD_GPIO_Init(void) { GPIOA->DIR |= 0 + // A7 = UART1 TX default as OUTPUT from bootloader! + // A8 = UART1 RX default as INPUT from bootloader! + // Key pad + I2C | GPIO_DIR_10_BITS_OUTPUT + // Key pad + I2C | GPIO_DIR_11_BITS_OUTPUT + // Key pad + Voice chip | GPIO_DIR_12_BITS_OUTPUT + // Key pad + Voice chip | GPIO_DIR_13_BITS_OUTPUT ; GPIOA->DIR &= ~(0 - | GPIO_DIR_3_MASK - | GPIO_DIR_4_MASK - | GPIO_DIR_5_MASK - | GPIO_DIR_6_MASK + // Key pad + | GPIO_DIR_3_MASK // INPUT + // Key pad + | GPIO_DIR_4_MASK // INPUT + // Key pad + | GPIO_DIR_5_MASK // INPUT + // Key pad + | GPIO_DIR_6_MASK // INPUT ); GPIOB->DIR |= 0 + // Back light | GPIO_DIR_6_BITS_OUTPUT + // ST7565 | GPIO_DIR_9_BITS_OUTPUT + // ST7565 + SWD IO | GPIO_DIR_11_BITS_OUTPUT + // B14 = SWD_CLK assumed INPUT by default + // BK1080 | GPIO_DIR_15_BITS_OUTPUT ; GPIOC->DIR |= 0 + // BK4819 SCN | GPIO_DIR_0_BITS_OUTPUT + // BK4819 SCL | GPIO_DIR_1_BITS_OUTPUT + // BK4819 SDA | GPIO_DIR_2_BITS_OUTPUT + // Flash light | GPIO_DIR_3_BITS_OUTPUT + // Speaker | GPIO_DIR_4_BITS_OUTPUT ; GPIOC->DIR &= ~(0 - | GPIO_DIR_5_MASK + // PTT button + | GPIO_DIR_5_MASK // INPUT ); #if defined(ENABLE_FMRADIO) @@ -94,128 +115,202 @@ void BOARD_GPIO_Init(void) void BOARD_PORTCON_Init(void) { - // TODO: Need to redo these macros to make more sense. - // PORT A pin selection - PORTCON_PORTA_SEL0 &= 0 - | PORTCON_PORTA_SEL0_A0_MASK - | PORTCON_PORTA_SEL0_A1_MASK - | PORTCON_PORTA_SEL0_A2_MASK - | PORTCON_PORTA_SEL0_A7_MASK - ; + PORTCON_PORTA_SEL0 &= ~(0 + // Key pad + | PORTCON_PORTA_SEL0_A3_MASK + // Key pad + | PORTCON_PORTA_SEL0_A4_MASK + // Key pad + | PORTCON_PORTA_SEL0_A5_MASK + // Key pad + | PORTCON_PORTA_SEL0_A6_MASK + ); PORTCON_PORTA_SEL0 |= 0 - | PORTCON_PORTA_SEL0_A0_BITS_GPIOA0 - | PORTCON_PORTA_SEL0_A1_BITS_GPIOA1 - | PORTCON_PORTA_SEL0_A2_BITS_GPIOA2 + // Key pad + | PORTCON_PORTA_SEL0_A3_BITS_GPIOA3 + // Key pad + | PORTCON_PORTA_SEL0_A4_BITS_GPIOA4 + // Key pad + | PORTCON_PORTA_SEL0_A5_BITS_GPIOA5 + // Key pad + | PORTCON_PORTA_SEL0_A6_BITS_GPIOA6 + // UART1 TX, wasn't cleared in previous step / relying on default value! | PORTCON_PORTA_SEL0_A7_BITS_UART1_TX ; - PORTCON_PORTA_SEL1 &= 0 - | PORTCON_PORTA_SEL1_A8_MASK - | PORTCON_PORTA_SEL1_A9_MASK - | PORTCON_PORTA_SEL1_A14_MASK - | PORTCON_PORTA_SEL1_A15_MASK - ; + PORTCON_PORTA_SEL1 &= ~(0 + // Key pad + I2C + | PORTCON_PORTA_SEL1_A10_MASK + // Key pad + I2C + | PORTCON_PORTA_SEL1_A11_MASK + // Key pad + Voice chip + | PORTCON_PORTA_SEL1_A12_MASK + // Key pad + Voice chip + | PORTCON_PORTA_SEL1_A13_MASK + ); PORTCON_PORTA_SEL1 |= 0 + // UART1 RX, wasn't cleared in previous step / relying on default value! | PORTCON_PORTA_SEL1_A8_BITS_UART1_RX + // Battery voltage, wasn't cleared in previous step / relying on default value! | PORTCON_PORTA_SEL1_A9_BITS_SARADC_CH4 + // Key pad + I2C + | PORTCON_PORTA_SEL1_A10_BITS_GPIOA10 + // Key pad + I2C + | PORTCON_PORTA_SEL1_A11_BITS_GPIOA11 + // Key pad + Voice chip + | PORTCON_PORTA_SEL1_A12_BITS_GPIOA12 + // Key pad + Voice chip + | PORTCON_PORTA_SEL1_A13_BITS_GPIOA13 + // Battery Current, wasn't cleared in previous step / relying on default value! | PORTCON_PORTA_SEL1_A14_BITS_SARADC_CH9 - | PORTCON_PORTA_SEL1_A15_BITS_GPIOA15 ; // PORT B pin selection - PORTCON_PORTB_SEL0 &= 0 - | PORTCON_PORTB_SEL0_B0_MASK - | PORTCON_PORTB_SEL0_B1_MASK - | PORTCON_PORTB_SEL0_B2_MASK - | PORTCON_PORTB_SEL0_B3_MASK - | PORTCON_PORTB_SEL0_B4_MASK - | PORTCON_PORTB_SEL0_B5_MASK - ; + PORTCON_PORTB_SEL0 &= ~(0 + // Back light + | PORTCON_PORTB_SEL0_B6_MASK + // SPI0 SSN + | PORTCON_PORTB_SEL0_B7_MASK + ); PORTCON_PORTB_SEL0 |= 0 - | PORTCON_PORTB_SEL0_B0_BITS_GPIOB0 - | PORTCON_PORTB_SEL0_B1_BITS_GPIOB1 - | PORTCON_PORTB_SEL0_B2_BITS_GPIOB2 - | PORTCON_PORTB_SEL0_B3_BITS_GPIOB3 - | PORTCON_PORTB_SEL0_B4_BITS_GPIOB4 - | PORTCON_PORTB_SEL0_B5_BITS_GPIOB5 + // Back light + | PORTCON_PORTB_SEL0_B6_BITS_GPIOB6 + // SPI0 SSN | PORTCON_PORTB_SEL0_B7_BITS_SPI0_SSN ; - PORTCON_PORTB_SEL1 &= 0 - | PORTCON_PORTB_SEL1_B8_MASK - | PORTCON_PORTB_SEL1_B10_MASK - | PORTCON_PORTB_SEL1_B12_MASK - | PORTCON_PORTB_SEL1_B13_MASK - ; + PORTCON_PORTB_SEL1 &= ~(0 + // ST7565 + | PORTCON_PORTB_SEL1_B9_MASK + // ST7565 + SWD IO + | PORTCON_PORTB_SEL1_B11_MASK + // SWD CLK + | PORTCON_PORTB_SEL1_B14_MASK + // BK1080 + | PORTCON_PORTB_SEL1_B15_MASK + ); PORTCON_PORTB_SEL1 |= 0 + // SPI0 CLK, wasn't cleared in previous step / relying on default value! | PORTCON_PORTB_SEL1_B8_BITS_SPI0_CLK + // ST7565 + | PORTCON_PORTB_SEL1_B9_BITS_GPIOB9 + // SPI0 MOSI, wasn't cleared in previous step / relying on default value! | PORTCON_PORTB_SEL1_B10_BITS_SPI0_MOSI +#if defined(ENABLE_SWD) + // SWD IO | PORTCON_PORTB_SEL1_B11_BITS_SWDIO - | PORTCON_PORTB_SEL1_B12_BITS_GPIOB12 - | PORTCON_PORTB_SEL1_B13_BITS_GPIOB13 + // SWD CLK | PORTCON_PORTB_SEL1_B14_BITS_SWCLK +#else + // ST7565 + | PORTCON_PORTB_SEL1_B11_BITS_GPIOB11 +#endif ; // PORT C pin selection - PORTCON_PORTC_SEL0 &= 0 - | PORTCON_PORTC_SEL0_C6_MASK - | PORTCON_PORTC_SEL0_C7_MASK - ; + PORTCON_PORTC_SEL0 &= ~(0 + // BK4819 SCN + | PORTCON_PORTC_SEL0_C0_MASK + // BK4819 SCL + | PORTCON_PORTC_SEL0_C1_MASK + // BK4819 SDA + | PORTCON_PORTC_SEL0_C2_MASK + // Flash light + | PORTCON_PORTC_SEL0_C3_MASK + // Speaker + | PORTCON_PORTC_SEL0_C4_MASK + // PTT button + | PORTCON_PORTC_SEL0_C5_MASK + ); // PORT A pin configuration PORTCON_PORTA_IE |= 0 + // Keypad | PORTCON_PORTA_IE_A3_BITS_ENABLE + // Keypad | PORTCON_PORTA_IE_A4_BITS_ENABLE + // Keypad | PORTCON_PORTA_IE_A5_BITS_ENABLE + // Keypad | PORTCON_PORTA_IE_A6_BITS_ENABLE + // A7 = UART1 TX disabled by default + // UART1 RX | PORTCON_PORTA_IE_A8_BITS_ENABLE ; PORTCON_PORTA_IE &= ~(0 + // Keypad + I2C | PORTCON_PORTA_IE_A10_MASK + // Keypad + I2C | PORTCON_PORTA_IE_A11_MASK + // Keypad + Voice chip | PORTCON_PORTA_IE_A12_MASK + // Keypad + Voice chip | PORTCON_PORTA_IE_A13_MASK ); PORTCON_PORTA_PU |= 0 + // Keypad | PORTCON_PORTA_PU_A3_BITS_ENABLE + // Keypad | PORTCON_PORTA_PU_A4_BITS_ENABLE + // Keypad | PORTCON_PORTA_PU_A5_BITS_ENABLE + // Keypad | PORTCON_PORTA_PU_A6_BITS_ENABLE ; PORTCON_PORTA_PU &= ~(0 + // Keypad + I2C | PORTCON_PORTA_PU_A10_MASK + // Keypad + I2C | PORTCON_PORTA_PU_A11_MASK + // Keypad + Voice chip | PORTCON_PORTA_PU_A12_MASK + // Keypad + Voice chip | PORTCON_PORTA_PU_A13_MASK ); PORTCON_PORTA_PD &= ~(0 + // Keypad | PORTCON_PORTA_PD_A3_MASK + // Keypad | PORTCON_PORTA_PD_A4_MASK + // Keypad | PORTCON_PORTA_PD_A5_MASK + // Keypad | PORTCON_PORTA_PD_A6_MASK + // Keypad + I2C | PORTCON_PORTA_PD_A10_MASK + // Keypad + I2C | PORTCON_PORTA_PD_A11_MASK + // Keypad + Voice chip | PORTCON_PORTA_PD_A12_MASK + // Keypad + Voice chip | PORTCON_PORTA_PD_A13_MASK ); PORTCON_PORTA_OD |= 0 + // Keypad | PORTCON_PORTA_OD_A3_BITS_ENABLE + // Keypad | PORTCON_PORTA_OD_A4_BITS_ENABLE + // Keypad | PORTCON_PORTA_OD_A5_BITS_ENABLE + // Keypad | PORTCON_PORTA_OD_A6_BITS_ENABLE ; PORTCON_PORTA_OD &= ~(0 + // Keypad + I2C | PORTCON_PORTA_OD_A10_MASK + // Keypad + I2C | PORTCON_PORTA_OD_A11_MASK + // Keypad + Voice chip | PORTCON_PORTA_OD_A12_MASK + // Keypad + Voice chip | PORTCON_PORTA_OD_A13_MASK ); @@ -225,82 +320,140 @@ void BOARD_PORTCON_Init(void) | PORTCON_PORTB_IE_B14_BITS_ENABLE ; PORTCON_PORTB_IE &= ~(0 + // Back light | PORTCON_PORTB_IE_B6_MASK + // UART1 | PORTCON_PORTB_IE_B7_MASK | PORTCON_PORTB_IE_B8_MASK + // ST7565 | PORTCON_PORTB_IE_B9_MASK + // SPI0 MOSI | PORTCON_PORTB_IE_B10_MASK +#if !defined(ENABLE_SWD) + // ST7565 + | PORTCON_PORTB_IE_B11_MASK +#endif + // BK1080 | PORTCON_PORTB_IE_B15_MASK ); PORTCON_PORTB_PU &= ~(0 + // Back light | PORTCON_PORTB_PU_B6_MASK + // ST7565 | PORTCON_PORTB_PU_B9_MASK + // ST7565 + SWD IO | PORTCON_PORTB_PU_B11_MASK + // SWD CLK | PORTCON_PORTB_PU_B14_MASK + // BK1080 | PORTCON_PORTB_PU_B15_MASK ); PORTCON_PORTB_PD &= ~(0 + // Back light | PORTCON_PORTB_PD_B6_MASK + // ST7565 | PORTCON_PORTB_PD_B9_MASK + // ST7565 + SWD IO | PORTCON_PORTB_PD_B11_MASK + // SWD CLK | PORTCON_PORTB_PD_B14_MASK + // BK1080 | PORTCON_PORTB_PD_B15_MASK ); PORTCON_PORTB_OD &= ~(0 + // Back light | PORTCON_PORTB_OD_B6_MASK + // ST7565 | PORTCON_PORTB_OD_B9_MASK + // ST7565 + SWD IO | PORTCON_PORTB_OD_B11_MASK + // BK1080 | PORTCON_PORTB_OD_B15_MASK ); PORTCON_PORTB_OD |= 0 + // SWD CLK | PORTCON_PORTB_OD_B14_BITS_ENABLE ; // PORT C pin configuration PORTCON_PORTC_IE |= 0 + // PTT button | PORTCON_PORTC_IE_C5_BITS_ENABLE ; PORTCON_PORTC_IE &= ~(0 + // BK4819 SCN | PORTCON_PORTC_IE_C0_MASK + // BK4819 SCL | PORTCON_PORTC_IE_C1_MASK + // BK4819 SDA | PORTCON_PORTC_IE_C2_MASK + // Flash Light | PORTCON_PORTC_IE_C3_MASK + // Speaker | PORTCON_PORTC_IE_C4_MASK ); PORTCON_PORTC_PU |= 0 + // PTT button | PORTCON_PORTC_PU_C5_BITS_ENABLE ; PORTCON_PORTC_PU &= ~(0 + // BK4819 SCN | PORTCON_PORTC_PU_C0_MASK + // BK4819 SCL | PORTCON_PORTC_PU_C1_MASK + // BK4819 SDA | PORTCON_PORTC_PU_C2_MASK + // Flash Light | PORTCON_PORTC_PU_C3_MASK + // Speaker | PORTCON_PORTC_PU_C4_MASK ); PORTCON_PORTC_PD &= ~(0 + // BK4819 SCN | PORTCON_PORTC_PD_C0_MASK + // BK4819 SCL | PORTCON_PORTC_PD_C1_MASK + // BK4819 SDA | PORTCON_PORTC_PD_C2_MASK + // Flash Light | PORTCON_PORTC_PD_C3_MASK + // Speaker | PORTCON_PORTC_PD_C4_MASK + // PTT Button | PORTCON_PORTC_PD_C5_MASK ); PORTCON_PORTC_OD &= ~(0 + // BK4819 SCN | PORTCON_PORTC_OD_C0_MASK + // BK4819 SCL | PORTCON_PORTC_OD_C1_MASK + // BK4819 SDA | PORTCON_PORTC_OD_C2_MASK + // Flash Light | PORTCON_PORTC_OD_C3_MASK + // Speaker | PORTCON_PORTC_OD_C4_MASK ); PORTCON_PORTC_OD |= 0 + // BK4819 SCN + | PORTCON_PORTC_OD_C0_BITS_DISABLE + // BK4819 SCL + | PORTCON_PORTC_OD_C1_BITS_DISABLE + // BK4819 SDA + | PORTCON_PORTC_OD_C2_BITS_DISABLE + // Flash Light + | PORTCON_PORTC_OD_C3_BITS_DISABLE + // Speaker + | PORTCON_PORTC_OD_C4_BITS_DISABLE + // PTT button | PORTCON_PORTC_OD_C5_BITS_ENABLE ; }