3636#include "py/mpconfig.h"
3737
3838digitalio_digitalinout_obj_t cs_pin ;
39- busio_spi_obj_t spi ;
39+ busio_spi_obj_t supervisor_flash_spi_bus ;
4040
4141const external_flash_device * flash_device ;
4242uint32_t spi_flash_baudrate ;
4343
4444// Enable the flash over SPI.
4545static void flash_enable (void ) {
46- while (!common_hal_busio_spi_try_lock (& spi )) {}
46+ while (!common_hal_busio_spi_try_lock (& supervisor_flash_spi_bus )) {}
4747 common_hal_digitalio_digitalinout_set_value (& cs_pin , false);
4848}
4949
5050// Disable the flash over SPI.
5151static void flash_disable (void ) {
5252 common_hal_digitalio_digitalinout_set_value (& cs_pin , true);
53- common_hal_busio_spi_unlock (& spi );
53+ common_hal_busio_spi_unlock (& supervisor_flash_spi_bus );
5454}
5555
5656static bool transfer (uint8_t * command , uint32_t command_length , uint8_t * data_in , uint8_t * data_out , uint32_t data_length ) {
5757 flash_enable ();
58- bool status = common_hal_busio_spi_write (& spi , command , command_length );
58+ bool status = common_hal_busio_spi_write (& supervisor_flash_spi_bus , command , command_length );
5959 if (status ) {
6060 if (data_in != NULL && data_out != NULL ) {
61- status = common_hal_busio_spi_transfer (& spi , data_out , data_in , data_length );
61+ status = common_hal_busio_spi_transfer (& supervisor_flash_spi_bus , data_out , data_in , data_length );
6262 } else if (data_out != NULL ) {
63- status = common_hal_busio_spi_read (& spi , data_out , data_length , 0xff );
63+ status = common_hal_busio_spi_read (& supervisor_flash_spi_bus , data_out , data_length , 0xff );
6464 } else if (data_in != NULL ) {
65- status = common_hal_busio_spi_write (& spi , data_in , data_length );
65+ status = common_hal_busio_spi_write (& supervisor_flash_spi_bus , data_in , data_length );
6666 }
6767 }
6868 flash_disable ();
@@ -103,10 +103,10 @@ bool spi_flash_write_data(uint32_t address, uint8_t* data, uint32_t data_length)
103103 // Write the SPI flash write address into the bytes following the command byte.
104104 address_to_bytes (address , request + 1 );
105105 flash_enable ();
106- common_hal_busio_spi_configure (& spi , spi_flash_baudrate , 0 , 0 , 8 );
107- bool status = common_hal_busio_spi_write (& spi , request , 4 );
106+ common_hal_busio_spi_configure (& supervisor_flash_spi_bus , spi_flash_baudrate , 0 , 0 , 8 );
107+ bool status = common_hal_busio_spi_write (& supervisor_flash_spi_bus , request , 4 );
108108 if (status ) {
109- status = common_hal_busio_spi_write (& spi , data , data_length );
109+ status = common_hal_busio_spi_write (& supervisor_flash_spi_bus , data , data_length );
110110 }
111111 flash_disable ();
112112 return status ;
@@ -122,10 +122,10 @@ bool spi_flash_read_data(uint32_t address, uint8_t* data, uint32_t data_length)
122122 // Write the SPI flash write address into the bytes following the command byte.
123123 address_to_bytes (address , request + 1 );
124124 flash_enable ();
125- common_hal_busio_spi_configure (& spi , spi_flash_baudrate , 0 , 0 , 8 );
126- bool status = common_hal_busio_spi_write (& spi , request , command_length );
125+ common_hal_busio_spi_configure (& supervisor_flash_spi_bus , spi_flash_baudrate , 0 , 0 , 8 );
126+ bool status = common_hal_busio_spi_write (& supervisor_flash_spi_bus , request , command_length );
127127 if (status ) {
128- status = common_hal_busio_spi_read (& spi , data , data_length , 0xff );
128+ status = common_hal_busio_spi_read (& supervisor_flash_spi_bus , data , data_length , 0xff );
129129 }
130130 flash_disable ();
131131 return status ;
@@ -140,9 +140,9 @@ void spi_flash_init(void) {
140140 common_hal_digitalio_digitalinout_switch_to_output (& cs_pin , true, DRIVE_MODE_PUSH_PULL );
141141 common_hal_digitalio_digitalinout_never_reset (& cs_pin );
142142
143- spi .base .type = & busio_spi_type ;
144- common_hal_busio_spi_construct (& spi , SPI_FLASH_SCK_PIN , SPI_FLASH_MOSI_PIN , SPI_FLASH_MISO_PIN );
145- common_hal_busio_spi_never_reset (& spi );
143+ supervisor_flash_spi_bus .base .type = & busio_spi_type ;
144+ common_hal_busio_spi_construct (& supervisor_flash_spi_bus , SPI_FLASH_SCK_PIN , SPI_FLASH_MOSI_PIN , SPI_FLASH_MISO_PIN );
145+ common_hal_busio_spi_never_reset (& supervisor_flash_spi_bus );
146146}
147147
148148void spi_flash_init_device (const external_flash_device * device ) {
0 commit comments