CommunityGD32Cores / ArduinoCore-GD32

Arduino core for GD32 devices, community developed, based on original GigaDevice's core
Other
85 stars 33 forks source link

GD_PORT_GET(X) and GD_PIN_GET(X) encoding error #125

Closed bmourit closed 2 months ago

bmourit commented 2 months ago

In order to work correctly, the macros defined in PinNames.h as: GD_PORT_GET(X) (((uint32_t)(X) >> 4) & 0xF) and GD_PIN_GET(X) (((uint32_t)(X) & 0xF)) expect the port and the ports' pin numbers to be encoded as above. However, this isn't happening in the code where we do something like eg: PORTA_15 = PORTA + 0x0F, PORTB_0 = PORTB + 0x10,

When the macros expect something like: PORTA_15 = (PORTA << 4) + 0x0F, PORTB_0 = (PORTB << 4) + 0x00,

Note the pin number starts at zero for each new port. This is required for the encoding to work. This will mean changes need to happen with the ADC_TEMP and ADC_VREF pins to prevent overlap.

We also have code that appears to expect the GPIOx port to be returned where the PORTx is instead. I'm not sure if the mapping is happening elsewhere, but for me it seems to not be happening.

bmourit commented 2 months ago

Closing since I had a clear brain freeze. lol