36
36
#include "py/mpconfig.h"
37
37
38
38
digitalio_digitalinout_obj_t cs_pin ;
39
- busio_spi_obj_t spi ;
39
+ busio_spi_obj_t supervisor_flash_spi_bus ;
40
40
41
41
const external_flash_device * flash_device ;
42
42
uint32_t spi_flash_baudrate ;
43
43
44
44
// Enable the flash over SPI.
45
45
static 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 )) {}
47
47
common_hal_digitalio_digitalinout_set_value (& cs_pin , false);
48
48
}
49
49
50
50
// Disable the flash over SPI.
51
51
static void flash_disable (void ) {
52
52
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 );
54
54
}
55
55
56
56
static bool transfer (uint8_t * command , uint32_t command_length , uint8_t * data_in , uint8_t * data_out , uint32_t data_length ) {
57
57
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 );
59
59
if (status ) {
60
60
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 );
62
62
} 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 );
64
64
} 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 );
66
66
}
67
67
}
68
68
flash_disable ();
@@ -103,10 +103,10 @@ bool spi_flash_write_data(uint32_t address, uint8_t* data, uint32_t data_length)
103
103
// Write the SPI flash write address into the bytes following the command byte.
104
104
address_to_bytes (address , request + 1 );
105
105
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 );
108
108
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 );
110
110
}
111
111
flash_disable ();
112
112
return status ;
@@ -122,10 +122,10 @@ bool spi_flash_read_data(uint32_t address, uint8_t* data, uint32_t data_length)
122
122
// Write the SPI flash write address into the bytes following the command byte.
123
123
address_to_bytes (address , request + 1 );
124
124
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 );
127
127
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 );
129
129
}
130
130
flash_disable ();
131
131
return status ;
@@ -140,9 +140,9 @@ void spi_flash_init(void) {
140
140
common_hal_digitalio_digitalinout_switch_to_output (& cs_pin , true, DRIVE_MODE_PUSH_PULL );
141
141
common_hal_digitalio_digitalinout_never_reset (& cs_pin );
142
142
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 );
146
146
}
147
147
148
148
void spi_flash_init_device (const external_flash_device * device ) {
0 commit comments