stm32/boards/LEGO_HUB_NO6: Use named pins.
This changes all uses of pins to use the alias names of the pins. This makes the code easier to understand and will also allow sharing more code with LEGO_HUB_NO7. Signed-off-by: David Lechner <david@pybricks.com>
This commit is contained in:
parent
6152bbe3dd
commit
7cc6df3303
@ -23,8 +23,13 @@ def update_app(filename):
|
||||
key = struct.pack("<I", _SPIFLASH_UPDATE_KEY_VALUE)
|
||||
|
||||
# Create a SPI flash object.
|
||||
spi = machine.SoftSPI(sck="B13", mosi="C3", miso="C2", baudrate=50_000_000)
|
||||
cs = machine.Pin("B12", machine.Pin.OUT, value=1)
|
||||
spi = machine.SoftSPI(
|
||||
sck=machine.Pin.board.FLASH_SCK,
|
||||
mosi=machine.Pin.board.FLASH_MOSI,
|
||||
miso=machine.Pin.board.FLASH_MISO,
|
||||
baudrate=50_000_000,
|
||||
)
|
||||
cs = machine.Pin(machine.Pin.board.FLASH_NSS, machine.Pin.OUT, value=1)
|
||||
flash = spiflash.SPIFlash(spi, cs)
|
||||
|
||||
# Write the update key and elements to the SPI flash.
|
||||
|
@ -113,7 +113,7 @@ static void board_led_pattern(int reset_mode, uint16_t brightness) {
|
||||
}
|
||||
|
||||
static void board_button_init(void) {
|
||||
mp_hal_pin_config(pin_A1, MP_HAL_PIN_MODE_ADC, MP_HAL_PIN_PULL_NONE, 0);
|
||||
mp_hal_pin_config(pyb_pin_BUTTONS_ADC, MP_HAL_PIN_MODE_ADC, MP_HAL_PIN_PULL_NONE, 0);
|
||||
adc_config(ADC1, 12);
|
||||
}
|
||||
|
||||
|
@ -81,7 +81,7 @@ static void hub_display_tim_init(void) {
|
||||
tim->CCR2 = 2;
|
||||
tim->EGR = 1; // UG
|
||||
|
||||
mp_hal_pin_config(pin_B15, MP_HAL_PIN_MODE_ALT, MP_HAL_PIN_PULL_NONE, 9);
|
||||
mp_hal_pin_config(pyb_pin_TLC_GS_CLK, MP_HAL_PIN_MODE_ALT, MP_HAL_PIN_PULL_NONE, 9);
|
||||
}
|
||||
|
||||
static void hub_display_spi_init(void) {
|
||||
@ -93,9 +93,9 @@ static void hub_display_spi_init(void) {
|
||||
spi->CR1 = SPI_CR1_SSM | SPI_CR1_SSI | 0 << SPI_CR1_BR_Pos | SPI_CR1_MSTR;
|
||||
spi->CR1 |= SPI_CR1_SPE;
|
||||
|
||||
mp_hal_pin_config(pin_A5, MP_HAL_PIN_MODE_ALT, MP_HAL_PIN_PULL_NONE, 5);
|
||||
mp_hal_pin_config(pin_A6, MP_HAL_PIN_MODE_ALT, MP_HAL_PIN_PULL_NONE, 5);
|
||||
mp_hal_pin_config(pin_A7, MP_HAL_PIN_MODE_ALT, MP_HAL_PIN_PULL_NONE, 5);
|
||||
mp_hal_pin_config(pyb_pin_TLC_SCLK, MP_HAL_PIN_MODE_ALT, MP_HAL_PIN_PULL_NONE, 5);
|
||||
mp_hal_pin_config(pyb_pin_TLC_SOUT, MP_HAL_PIN_MODE_ALT, MP_HAL_PIN_PULL_NONE, 5);
|
||||
mp_hal_pin_config(pyb_pin_TLC_SIN, MP_HAL_PIN_MODE_ALT, MP_HAL_PIN_PULL_NONE, 5);
|
||||
}
|
||||
|
||||
static void hub_display_spi_write(uint8_t value) {
|
||||
@ -123,9 +123,9 @@ static void hub_display_latch_ctrl(uint8_t dc, uint32_t mc, uint32_t bc, uint8_t
|
||||
for (int i = 0; i < 42; ++i) {
|
||||
hub_display_spi_write(dc);
|
||||
}
|
||||
mp_hal_pin_high(pin_A15);
|
||||
mp_hal_pin_high(pyb_pin_TLC_LAT);
|
||||
mp_hal_delay_us(1);
|
||||
mp_hal_pin_low(pin_A15);
|
||||
mp_hal_pin_low(pyb_pin_TLC_LAT);
|
||||
}
|
||||
|
||||
void hub_display_set(uint8_t led, uint16_t value) {
|
||||
@ -142,17 +142,17 @@ void hub_display_update(void) {
|
||||
for (int i = 0; i < 96; ++i) {
|
||||
hub_display_spi_write(hub_display_gs_state[95 - i]);
|
||||
}
|
||||
mp_hal_pin_high(pin_A15);
|
||||
mp_hal_pin_high(pyb_pin_TLC_LAT);
|
||||
mp_hal_delay_us(1);
|
||||
mp_hal_pin_low(pin_A15);
|
||||
mp_hal_pin_low(pyb_pin_TLC_LAT);
|
||||
}
|
||||
|
||||
void hub_display_on(void) {
|
||||
if (hub_display_init) {
|
||||
return;
|
||||
}
|
||||
mp_hal_pin_output(pin_A15);
|
||||
mp_hal_pin_low(pin_A15);
|
||||
mp_hal_pin_output(pyb_pin_TLC_LAT);
|
||||
mp_hal_pin_low(pyb_pin_TLC_LAT);
|
||||
hub_display_spi_init();
|
||||
for (int i = 0; i < 2; ++i) {
|
||||
hub_display_latch_ctrl(0xff, 0, 0x1fffff, 0x11);
|
||||
@ -171,10 +171,10 @@ void hub_display_off(void) {
|
||||
__HAL_RCC_SPI1_CLK_DISABLE();
|
||||
__HAL_RCC_SPI1_FORCE_RESET();
|
||||
__HAL_RCC_SPI1_RELEASE_RESET();
|
||||
mp_hal_pin_config(pin_A5, MP_HAL_PIN_MODE_ANALOG, MP_HAL_PIN_PULL_NONE, 0);
|
||||
mp_hal_pin_config(pin_A6, MP_HAL_PIN_MODE_ANALOG, MP_HAL_PIN_PULL_NONE, 0);
|
||||
mp_hal_pin_config(pin_A7, MP_HAL_PIN_MODE_ANALOG, MP_HAL_PIN_PULL_NONE, 0);
|
||||
mp_hal_pin_config(pin_A15, MP_HAL_PIN_MODE_ANALOG, MP_HAL_PIN_PULL_NONE, 0);
|
||||
mp_hal_pin_config(pin_B15, MP_HAL_PIN_MODE_ANALOG, MP_HAL_PIN_PULL_NONE, 0);
|
||||
mp_hal_pin_config(pyb_pin_TLC_SCLK, MP_HAL_PIN_MODE_ANALOG, MP_HAL_PIN_PULL_NONE, 0);
|
||||
mp_hal_pin_config(pyb_pin_TLC_SOUT, MP_HAL_PIN_MODE_ANALOG, MP_HAL_PIN_PULL_NONE, 0);
|
||||
mp_hal_pin_config(pyb_pin_TLC_SIN, MP_HAL_PIN_MODE_ANALOG, MP_HAL_PIN_PULL_NONE, 0);
|
||||
mp_hal_pin_config(pyb_pin_TLC_LAT, MP_HAL_PIN_MODE_ANALOG, MP_HAL_PIN_PULL_NONE, 0);
|
||||
mp_hal_pin_config(pyb_pin_TLC_GS_CLK, MP_HAL_PIN_MODE_ANALOG, MP_HAL_PIN_PULL_NONE, 0);
|
||||
hub_display_init = false;
|
||||
}
|
||||
|
@ -34,41 +34,40 @@
|
||||
|
||||
// UART buses
|
||||
// Bluetooth HCI
|
||||
#define MICROPY_HW_UART2_CTS (pin_D3)
|
||||
#define MICROPY_HW_UART2_RTS (pin_D4)
|
||||
#define MICROPY_HW_UART2_TX (pin_D5)
|
||||
#define MICROPY_HW_UART2_RX (pin_D6)
|
||||
#define MICROPY_HW_UART2_CTS (pyb_pin_BT_CTS)
|
||||
#define MICROPY_HW_UART2_RTS (pyb_pin_BT_RTS)
|
||||
#define MICROPY_HW_UART2_TX (pyb_pin_BT_TX)
|
||||
#define MICROPY_HW_UART2_RX (pyb_pin_BT_RX)
|
||||
// Port B
|
||||
#define MICROPY_HW_UART4_TX (pin_D1)
|
||||
#define MICROPY_HW_UART4_RX (pin_D0)
|
||||
#define MICROPY_HW_UART4_TX (pyb_pin_PORTB_TX)
|
||||
#define MICROPY_HW_UART4_RX (pyb_pin_PORTB_RX)
|
||||
// Port D
|
||||
#define MICROPY_HW_UART5_TX (pin_C12)
|
||||
#define MICROPY_HW_UART5_RX (pin_D2)
|
||||
#define MICROPY_HW_UART5_TX (pyb_pin_PORTD_TX)
|
||||
#define MICROPY_HW_UART5_RX (pyb_pin_PORTD_RX)
|
||||
// Port A
|
||||
#define MICROPY_HW_UART7_TX (pin_E8)
|
||||
#define MICROPY_HW_UART7_RX (pin_E7)
|
||||
#define MICROPY_HW_UART7_TX (pyb_pin_PORTA_TX)
|
||||
#define MICROPY_HW_UART7_RX (pyb_pin_PORTA_RX)
|
||||
// Port C
|
||||
#define MICROPY_HW_UART8_TX (pin_E1)
|
||||
#define MICROPY_HW_UART8_RX (pin_E0)
|
||||
#define MICROPY_HW_UART8_TX (pyb_pin_PORTC_TX)
|
||||
#define MICROPY_HW_UART8_RX (pyb_pin_PORTC_RX)
|
||||
// Port F
|
||||
#define MICROPY_HW_UART9_TX (pin_D15)
|
||||
#define MICROPY_HW_UART9_RX (pin_D14)
|
||||
#define MICROPY_HW_UART9_TX (pyb_pin_PORTF_TX)
|
||||
#define MICROPY_HW_UART9_RX (pyb_pin_PORTF_RX)
|
||||
// Port E
|
||||
#define MICROPY_HW_UART10_TX (pin_E3)
|
||||
#define MICROPY_HW_UART10_RX (pin_E2)
|
||||
#define MICROPY_HW_UART10_TX (pyb_pin_PORTE_TX)
|
||||
#define MICROPY_HW_UART10_RX (pyb_pin_PORTE_RX)
|
||||
|
||||
// SPI buses
|
||||
#define MICROPY_HW_SPI1_NSS (pin_A4) // shared with DAC
|
||||
#define MICROPY_HW_SPI1_SCK (pin_A5) // shared with DAC
|
||||
#define MICROPY_HW_SPI1_MISO (pin_A6)
|
||||
#define MICROPY_HW_SPI1_MOSI (pin_A7)
|
||||
#define MICROPY_HW_SPI2_NSS (pin_B12)
|
||||
#define MICROPY_HW_SPI2_SCK (pin_B13)
|
||||
#define MICROPY_HW_SPI2_MISO (pin_C2)
|
||||
#define MICROPY_HW_SPI2_MOSI (pin_C3)
|
||||
#define MICROPY_HW_SPI1_SCK (pyb_pin_TLC_SCLK)
|
||||
#define MICROPY_HW_SPI1_MISO (pyb_pin_TLC_SOUT)
|
||||
#define MICROPY_HW_SPI1_MOSI (pyb_pin_TLC_SIN)
|
||||
#define MICROPY_HW_SPI2_NSS (pyb_pin_FLASH_NSS)
|
||||
#define MICROPY_HW_SPI2_SCK (pyb_pin_FLASH_SCK)
|
||||
#define MICROPY_HW_SPI2_MISO (pyb_pin_FLASH_MISO)
|
||||
#define MICROPY_HW_SPI2_MOSI (pyb_pin_FLASH_MOSI)
|
||||
|
||||
// USB config
|
||||
#define MICROPY_HW_USB_VBUS_DETECT_PIN (pin_A9)
|
||||
#define MICROPY_HW_USB_VBUS_DETECT_PIN (pyb_pin_USB_VBUS)
|
||||
#define MICROPY_HW_USB_FS (1)
|
||||
#define MICROPY_HW_USB_MSC (1)
|
||||
|
||||
|
@ -26,14 +26,14 @@ PORTD_M1,PB8
|
||||
PORTD_M2,PB9
|
||||
LSM6_SCL,PB10
|
||||
,PB11
|
||||
,PB12
|
||||
,PB13
|
||||
FLASH_NSS,PB12
|
||||
FLASH_SCK,PB13
|
||||
,PB14
|
||||
TLC_GS_CLK,PB15
|
||||
BAT_IMON_ADC,PC0
|
||||
BAT_VMON_ADC,PC1
|
||||
,PC2
|
||||
,PC3
|
||||
FLASH_MISO,PC2
|
||||
FLASH_MOSI,PC3
|
||||
CHGOK_CENBTN_3V3OK_ADC,PC4
|
||||
PORTF_EN,PC5
|
||||
PORTE_M1,PC6
|
||||
|
|
Loading…
x
Reference in New Issue
Block a user