I can blink the onboard LED of the Trinket M0 from MicroPython
I will need some help to organize the PIN declaration for multiple SAMD21 board (Trinket M0, Itsy Bitsy M0, Feather M0, Gemma M0).
Primilarily work
Presently that LED is assigned to PA10, so I defined a primilary machine_pin_obj (in machine_pin.c) with pins for 0 to 10 corresponding to PA00 to PA10. This definition was done for test/development purpose.
Code: Select all
STATIC const machine_pin_obj_t machine_pin_obj[] = {
{{&machine_pin_type}, PIN_PA00, 0x00 | 0},
{{&machine_pin_type}, PIN_PA01, 0x00 | 1},
{{&machine_pin_type}, PIN_PA02, 0x00 | 2},
{{&machine_pin_type}, PIN_PA03, 0x00 | 3},
{{&machine_pin_type}, PIN_PA04, 0x00 | 4},
{{&machine_pin_type}, PIN_PA05, 0x00 | 5},
{{&machine_pin_type}, PIN_PA06, 0x00 | 6},
{{&machine_pin_type}, PIN_PA07, 0x00 | 7},
{{&machine_pin_type}, PIN_PA08, 0x00 | 8},
{{&machine_pin_type}, PIN_PA09, 0x00 | 9},
{{&machine_pin_type}, PIN_PA10, 0x00 | 10},
{{&machine_pin_type}, PIN_PA11, 0x00 | 11},
{{NULL}, -1, -1},
{{NULL}, -1, -1},
{{&machine_pin_type}, PIN_PA14, 0x00 | 14},
{{&machine_pin_type}, PIN_PA15, 0x00 | 15},
{{&machine_pin_type}, PIN_PA16, 0x00 | 16},
{{&machine_pin_type}, PIN_PA17, 0x00 | 17},
{{&machine_pin_type}, PIN_PA18, 0x00 | 18},
{{&machine_pin_type}, PIN_PA19, 0x00 | 19},
{{NULL}, -1, -1},
{{NULL}, -1, -1},
{{&machine_pin_type}, PIN_PA22, 0x00 | 22},
{{&machine_pin_type}, PIN_PA23, 0x00 | 23},
{{&machine_pin_type}, PIN_PA24, 0x00 | 24},
{{&machine_pin_type}, PIN_PA25, 0x00 | 25},
{{NULL}, -1, -1},
{{&machine_pin_type}, PIN_PA27, 0x00 | 27},
{{&machine_pin_type}, PIN_PA28, 0x00 | 28},
{{NULL}, -1, -1},
{{&machine_pin_type}, PIN_PA30, 0x00 | 30},
{{&machine_pin_type}, PIN_PA31, 0x00 | 31},
};
Code: Select all
from machine import Pin
p = Pin( 10, Pin.OUT ) # presently match PA10
p.value( 1 ) # light up the LED
However, on the Trinket M0, the LED (wired to PA10) is labelled as Pin #13. So the machine_pin_obj should be deifined in such a way to have the 13th position associated to PIN_PA10.
This will ONLY covers the Trinket M0 use-case. The feather M0 or ItsyBitsy M0 or Gemma M0 will have a different definition of machine_pin_obj because of different MCU pin assignment on the board.
My current approach
My current approach will be add a #define HW_BOARD_ADAFRUIT_TRINKET_M0 in the boards/ADAFRUIT_TRINKET_M0/mpconfigboard.h file.
Then a #ifdef HW_BOARD_ADAFRUIT_TRINKET_M0 will be used to defined the proper machine_pin_obj at compile time in the machine_pin.h .
Is there a better way?
It should be a better MicroPython way of doing my pin assignment.
If someone could advice, that would be really great!
Cheers,
Dominique