Skip to content

Instantly share code, notes, and snippets.

@xidameng
Last active August 29, 2021 02:34
Show Gist options
  • Save xidameng/aca32c0c8f1ec1dd1faf10416ee3e07d to your computer and use it in GitHub Desktop.
Save xidameng/aca32c0c8f1ec1dd1faf10416ee3e07d to your computer and use it in GitHub Desktop.
There are 2 files need to update in order to add support for more GPIO pins
// "variant.cpp"
PinDescription g_APinDescription[TOTAL_GPIO_PIN_NUM]=
{
{PB_2, NOT_INITIAL, PIO_GPIO | PIO_GPIO_IRQ , NOT_INITIAL}, //D0
{PB_1, NOT_INITIAL, PIO_GPIO | PIO_GPIO_IRQ , NOT_INITIAL}, //D1
{PB_3, NOT_INITIAL, PIO_GPIO | PIO_GPIO_IRQ , NOT_INITIAL}, //D2
{PB_31, NOT_INITIAL, PIO_GPIO | PIO_GPIO_IRQ , NOT_INITIAL}, //D3
{PB_30, NOT_INITIAL, PIO_GPIO | PIO_GPIO_IRQ , NOT_INITIAL}, //D4
{PB_28, NOT_INITIAL, PIO_GPIO | PIO_GPIO_IRQ , NOT_INITIAL}, //D5
{PB_29, NOT_INITIAL, PIO_GPIO | PIO_GPIO_IRQ , NOT_INITIAL}, //D6
{NC, NOT_INITIAL, NOT_INITIAL , NOT_INITIAL}, //D7
{PB_22, NOT_INITIAL, PIO_GPIO | PIO_GPIO_IRQ | PIO_PWM , NOT_INITIAL}, //D8
{PB_23, NOT_INITIAL, PIO_GPIO | PIO_GPIO_IRQ | PIO_PWM , NOT_INITIAL}, //D9
{PB_21, NOT_INITIAL, PIO_GPIO | PIO_GPIO_IRQ | PIO_PWM , NOT_INITIAL}, //D10
{PB_18, NOT_INITIAL, PIO_GPIO | PIO_GPIO_IRQ | PIO_PWM , NOT_INITIAL}, //D11
{PB_19, NOT_INITIAL, PIO_GPIO | PIO_GPIO_IRQ | PIO_PWM , NOT_INITIAL}, //D12
{PB_20, NOT_INITIAL, PIO_GPIO | PIO_GPIO_IRQ | PIO_PWM , NOT_INITIAL}, //D13
{PA_7, NOT_INITIAL, PIO_GPIO | PIO_GPIO_IRQ , NOT_INITIAL}, //D14
{PA_8, NOT_INITIAL, PIO_GPIO | PIO_GPIO_IRQ , NOT_INITIAL}, //D15
{PA_25, NOT_INITIAL, PIO_GPIO | PIO_GPIO_IRQ | PIO_PWM , NOT_INITIAL}, //D16
{PA_26, NOT_INITIAL, PIO_GPIO | PIO_GPIO_IRQ | PIO_PWM , NOT_INITIAL}, //D17
{PB_7, NOT_INITIAL, PIO_GPIO | PIO_GPIO_IRQ | PIO_PWM , NOT_INITIAL}, //D18
{PB_6, NOT_INITIAL, PIO_GPIO | PIO_GPIO_IRQ , NOT_INITIAL}, //D19
{PB_5, NOT_INITIAL, PIO_GPIO | PIO_GPIO_IRQ | PIO_PWM , NOT_INITIAL}, //D20
{PB_4, NOT_INITIAL, PIO_GPIO | PIO_GPIO_IRQ | PIO_PWM , NOT_INITIAL}, //D21
{PA_28, NOT_INITIAL, PIO_GPIO | PIO_GPIO_IRQ , NOT_INITIAL}, //D22
{PA_24, NOT_INITIAL, PIO_GPIO | PIO_GPIO_IRQ | PIO_PWM , NOT_INITIAL}, //D23
{PA_23, NOT_INITIAL, PIO_GPIO | PIO_GPIO_IRQ | PIO_PWM , NOT_INITIAL}, //D24
{PA_22, NOT_INITIAL, PIO_GPIO | PIO_GPIO_IRQ , NOT_INITIAL}, //D25
{PA_21, NOT_INITIAL, PIO_GPIO | PIO_GPIO_IRQ , NOT_INITIAL}, //D26
{PA_20, NOT_INITIAL, PIO_GPIO | PIO_GPIO_IRQ , NOT_INITIAL}, //D27
{PA_19, NOT_INITIAL, PIO_GPIO | PIO_GPIO_IRQ , NOT_INITIAL}, //D28
{PA_12, NOT_INITIAL, PIO_GPIO | PIO_GPIO_IRQ , NOT_INITIAL} //D29 This pin is on the male header!
};
/////////////////////////////////////////////////////////
// "varient.h
#define TOTAL_GPIO_PIN_NUM (30) // default is 29, you should increment this number with the number of new pins added
@xidameng
Copy link
Author

It does, please take a closer look at the last line of my gist, you have to increment the macro "TOTAL_GPIO_PIN_NUM " under variant.h before you can add new line.

Also, you shouldn't delete any existing pin declaration from the matrix, you should only add new lines following the end of the last line in the matrix.

@xidameng
Copy link
Author

why not you try and copy my code and paste to both variant.cpp and variant.h? I have just tested it, and it works for me ;)

@ajsb85
Copy link

ajsb85 commented Aug 28, 2021

Oh, nice.

I didn't saw the last line. 🤦‍♂️
I need to familiarize with the source code at all.

PB[24] = HS_USI_I2C_SCL
PB[25] = HS_USI_I2C_SDA

Can you please help me to enable these I2C port?

@xidameng
Copy link
Author

Oh, nice.

I didn't saw the last line. 🤦‍♂️
I need to familiarize with the source code at all.

PB[24] = HS_USI_I2C_SCL
PB[25] = HS_USI_I2C_SDA

Can you please help me to enable these I2C port?

Hi, to add new set of I2C, you should look at this line,
https://github.com/ambiot/ambd_arduino/blob/5b62e45d6721404532d12c3c5397033723f92acd/Arduino_package/hardware/libraries/Wire/Wire.cpp#L275

e.g.:
TwoWire Wire2 = TwoWire(PB_25, PB_24);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment