Skip to content

Commit

Permalink
Figuring out how to do board setup and reset
Browse files Browse the repository at this point in the history
  • Loading branch information
ZodiusInfuser committed Aug 11, 2023
1 parent 44a955d commit 30686d6
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 2 deletions.
50 changes: 50 additions & 0 deletions firmware/PIMORONI_YUKON/board_init.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
#include "hardware/gpio.h"
#include "hardware/i2c.h"
#include "drivers/tca9555/tca9555.h"

void board_init() {
gpio_init(8);
gpio_set_dir(8, GPIO_OUT);
gpio_put(8, true);
configure_i2c();
gpio_put(8, false);

gpio_init(9);
gpio_set_dir(9, GPIO_OUT);
gpio_put(9, true);
sleep_us(100);
gpio_put(9, false);
sleep_us(10);
gpio_put(9, true);
// Set the first IO expander's initial state
tca_set_output_port(0, 0x0000);
tca_set_polarity_port(0, 0x0000);
tca_set_config_port(0, 0x07BF);

// Set the second IO expander's initial state
tca_set_output_port(1, 0x0000);
tca_set_polarity_port(1, 0x0000);
tca_set_config_port(1, 0xFCE6);
sleep_us(100);
gpio_put(9, false);
}

void board_reset(void) {
for (int i = 0; i < 24; ++i) {
gpio_init(i);
hw_clear_bits(&padsbank0_hw->io[i], PADS_BANK0_GPIO0_IE_BITS |
PADS_BANK0_GPIO0_PUE_BITS |
PADS_BANK0_GPIO0_PDE_BITS);
hw_set_bits(&padsbank0_hw->io[i], PADS_BANK0_GPIO0_OD_BITS);
}

// Set the first IO expander's initial state
tca_set_output_port(0, 0x0000);
tca_set_polarity_port(0, 0x0000);
tca_set_config_port(0, 0x07BF);

// Set the second IO expander's initial state
tca_set_output_port(1, 0x0000);
tca_set_polarity_port(1, 0x0000);
tca_set_config_port(1, 0xFCE6);
}
4 changes: 4 additions & 0 deletions firmware/PIMORONI_YUKON/mpconfigboard.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ set(MICROPY_BOARD "pimoroni_yukon")
# Allow Pico SDK to locate "pimoroni_yukon.h" in this directory.
list(APPEND PICO_BOARD_HEADER_DIRS "${CMAKE_CURRENT_LIST_DIR}")

set(MICROPY_SOURCE_BOARD
${CMAKE_CURRENT_LIST_DIR}/board_init.c
)

# Board specific version of the frozen manifest
set(MICROPY_FROZEN_MANIFEST ${CMAKE_CURRENT_LIST_DIR}/manifest.py)

Expand Down
14 changes: 12 additions & 2 deletions firmware/PIMORONI_YUKON/mpconfigboard.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
#define MICROPY_HW_SPI0_MOSI (0)
#define MICROPY_HW_SPI0_MISO (0)

#define MICROPY_HW_I2C0_SDA (24)
#define MICROPY_HW_I2C0_SCL (25)

// Enable networking.
//#define MICROPY_PY_NETWORK 1
//#define MICROPY_PY_NETWORK_HOSTNAME_DEFAULT "Yukon"
Expand All @@ -23,6 +26,13 @@
// Debug level (0-4) 1=warning, 2=info, 3=debug, 4=verbose
// #define MODUSSL_MBEDTLS_DEBUG_LEVEL 1

//#define MICROPY_HW_PIN_EXT_COUNT CYW43_WL_GPIO_COUNT
#define MICROPY_PY_TCA9555 (1)
#define MICROPY_HW_PIN_EXT_COUNT (32)

//#define MICROPY_HW_PIN_RESERVED(i) ((i) == CYW43_PIN_WL_HOST_WAKE || (i) == CYW43_PIN_WL_REG_ON)

#define MICROPY_BOARD_EARLY_INIT board_init
void board_init(void);

//#define MICROPY_HW_PIN_RESERVED(i) ((i) == CYW43_PIN_WL_HOST_WAKE || (i) == CYW43_PIN_WL_REG_ON)
#define MICROPY_BOARD_PRE_RUNTIME_RESET board_reset
void board_reset(void);

0 comments on commit 30686d6

Please sign in to comment.