34
34
#include "shared-bindings/microcontroller/__init__.h"
35
35
36
36
/*
37
- * Current pin limitations:
38
- * data0 pin must be byte aligned and use pin numbers < 32 (data0 options: 0, 8, 16 or 24)
39
- * write pin must be pin number < 32.
40
- *
41
- * Future extensions:
42
- * 1. Allow data0 pin numbers >= 32.
43
- * 2. Allow write pin numbers >= 32.
44
- */
37
+ *
38
+ * Current pin limitations for ESP32-S2 ParallelBus:
39
+ * 1. data0 pin must be byte aligned (data0 pin options: 0, 8, 16 or 24)
40
+ * 2. The 8 data lines must use pin numbers < 32
41
+ * 3. The write pin must be pin number < 32.
42
+ *
43
+ */
45
44
46
45
void common_hal_displayio_parallelbus_construct (displayio_parallelbus_obj_t * self ,
47
46
const mcu_pin_obj_t * data0 , const mcu_pin_obj_t * command , const mcu_pin_obj_t * chip_select ,
48
47
const mcu_pin_obj_t * write , const mcu_pin_obj_t * read , const mcu_pin_obj_t * reset ) {
49
48
50
-
51
49
uint8_t data_pin = data0 -> number ;
52
50
if ( (data_pin % 8 != 0 ) && (data_pin >= 32 ) ) {
53
51
mp_raise_ValueError (translate ("Data 0 pin must be byte aligned and < 32" ));
@@ -63,21 +61,22 @@ void common_hal_displayio_parallelbus_construct(displayio_parallelbus_obj_t* sel
63
61
mp_raise_ValueError (translate ("Write pin must be < 32" ));
64
62
}
65
63
66
- gpio_dev_t * g = & GPIO ; /* this is the GPIO registers, see "extern gpio_dev_t GPIO" from file:gpio_struct.h */
64
+ gpio_dev_t * g = & GPIO ; // this is the GPIO registers, see "extern gpio_dev_t GPIO" from file:gpio_struct.h
67
65
68
- /* Setup the pins as "Simple GPIO outputs" see section 19.3.3 of the ESP32-S2 Reference Manual */
69
- /* Enable pins with "enable_w1ts" */
66
+ // Setup the pins as "Simple GPIO outputs" see section 19.3.3 of the ESP32-S2 Reference Manual
67
+ // Enable pins with "enable_w1ts"
70
68
71
69
for (uint8_t i = 0 ; i < 8 ; i ++ ) {
72
70
g -> enable_w1ts = (0x1 << (data_pin + i ));
73
71
g -> func_out_sel_cfg [data_pin + i ].val = 256 ; /* setup output pin for simple GPIO Output, (0x100 = 256) */
74
72
75
73
}
76
74
77
- /* I think there is a limitation of the ESP32-S2 that does not allow single-byte writes into
78
- the GPIO registers. See section 10.3.3 regarding "non-aligned writes" into the registers.
79
- If a method for writing single-byte writes is uncovered, this code can be modified to provide
80
- single-byte access into the output register */
75
+ /* From my understanding, there is a limitation of the ESP32-S2 that does not allow single-byte writes
76
+ * into the GPIO registers. See section 10.3.3 regarding "non-aligned writes" into the registers.
77
+ * If a method for writing single-byte writes is uncovered, this code can be modified to provide
78
+ * single-byte access into the output register
79
+ */
81
80
82
81
self -> bus = (uint32_t * ) & g -> out ; //pointer to GPIO output register (for pins 0-31)
83
82
@@ -100,14 +99,16 @@ void common_hal_displayio_parallelbus_construct(displayio_parallelbus_obj_t* sel
100
99
101
100
self -> data0_pin = data_pin ;
102
101
self -> write_group = & GPIO ;
103
- /* Should modify the .h structure definitions if want to allow a write pin >= 32.
104
- If so, consider putting separate "clear_write" and "set_write" pointers into the .h in place of "write_group"
105
- to select between out_w1tc/out1_w1tc (clear) and out_w1ts/out1_w1ts (set) registers. */
102
+ /* If we want to allow a write pin >= 32, should consider putting separate "clear_write" and
103
+ * "set_write" pointers into the .h in place of "write_group"
104
+ * to select between out_w1tc/out1_w1tc (clear) and out_w1ts/out1_w1ts (set) registers.
105
+ */
106
106
107
107
self -> write_mask = 1 << (write -> number % 32 ); /* the write pin triggers the LCD to latch the data */
108
108
/* Note: As currently written for the ESP32-S2 port, the write pin must be a pin number less than 32
109
- This could be updated to accommodate 32 and higher by using the different construction of the
110
- address for writing to output pins >= 32, see related note above for 'self->write_group' */
109
+ * This could be updated to accommodate 32 and higher by using the different construction of the
110
+ * address for writing to output pins >= 32, see related note above for 'self->write_group'
111
+ */
111
112
112
113
/* SNIP - common setup of the reset pin, same as from SAMD and NRF ports */
113
114
self -> reset .base .type = & mp_type_NoneType ;
@@ -174,57 +175,44 @@ void common_hal_displayio_parallelbus_send(mp_obj_t obj, display_byte_type_t byt
174
175
common_hal_digitalio_digitalinout_set_value (& self -> command , byte_type == DISPLAY_DATA );
175
176
176
177
/* Currently the write pin number must be < 32.
177
- Future: To accommodate write pin numbers >= 32, will need to update to choose a different register
178
- for set/reset (out1_w1tc and out1_w1ts) */
179
-
180
- // **** Bit shifting trial
181
- // uint32_t* output_register = self->bus;
182
- // const uint8_t bit_shift=self->data0_pin;
178
+ * Future: To accommodate write pin numbers >= 32, will need to update to choose the correct register
179
+ * for the write pin set/clear (out_w1ts/out1_w1ts and out_w1tc/out1_w1tc)
180
+ */
183
181
184
182
uint32_t * clear_write = (uint32_t * ) & self -> write_group -> out_w1tc ;
185
183
uint32_t * set_write = (uint32_t * ) & self -> write_group -> out_w1ts ;
186
184
187
185
const uint32_t mask = self -> write_mask ;
188
186
189
-
190
187
/* Setup structures for data writing. The ESP32-S2 port differs from the SAMD and NRF ports
191
- because I have not found a way to write a single byte into the ESP32-S2 registers.
192
- For the ESP32-S2, I create a 32-bit data_buffer that is used to transfer the data bytes. */
188
+ * because I have not found a way to write a single byte into the ESP32-S2 registers.
189
+ * For the ESP32-S2, I create a 32-bit data_buffer that is used to transfer the data bytes.
190
+ */
193
191
194
- * clear_write = mask ; // Clear the write pin to prepare the registers before storing register settings into data_buffer
192
+ * clear_write = mask ; // Clear the write pin to prepare the registers before storing the
193
+ // register value into data_buffer
195
194
196
195
const uint32_t data_buffer = * self -> bus ; // store the initial output register values into the data output buffer
197
196
uint8_t * data_address = ((uint8_t * ) & data_buffer ) + (self -> data0_pin / 8 ); /* address inside data_buffer where
198
- each data byte will be written (as offset by (data0_pin/8) number of bytes) */
199
-
200
- // *** Bit shifting trial
201
- // *data_address = 0; //clear the 8 data bits
202
-
203
- //mp_printf(&mp_plat_print, "\n\ndata_buffer: %x\n", data_buffer);
204
- //mp_printf(&mp_plat_print, "data[0]: %x\n", data[0]);
205
- //mp_printf(&mp_plat_print, "data_buffer[0]: %x\n\n", (data_buffer | (((uint32_t) data[0]) << self->data0_pin)));
197
+ * each data byte will be written to the data pin registers
198
+ */
206
199
207
200
for (uint32_t i = 0 ; i < data_length ; i ++ ) {
208
201
209
202
/* Question: Is there a faster way of stuffing the data byte into the data_buffer, is bit arithmetic
210
- faster than writing to the byte address? */
203
+ * faster than writing to the byte address?
204
+ */
211
205
212
- /* Note: May be able to eliminate either the clear_write or set_write since the data buffer
213
- can be written with the write pin cleared or set already, and depending upon whether the display
214
- latches the data on the rising or falling edge of the write pin. Remember: This method
215
- will require the write pin to be controlled by the same GPIO register as the data pins. */
206
+ /* Note: If the write pin and data pins are controlled by the same GPIO register, we can eliminate
207
+ * the "clear_write" step below, since the write pin is cleared when the data_buffer is written
208
+ * to the bus.
209
+ * Remember: This method requires the write pin to be controlled by the same GPIO register as the data pins.
210
+ */
216
211
217
- // Can ignore this line if the write pin is in the same register as the data pins
218
212
// *clear_write = mask; // clear the write pin (See comment above, this may not be necessary).
219
213
220
- // *** Original code
221
214
* (data_address ) = data [i ]; // stuff the data byte into the data_buffer at the correct offset byte location
222
215
* self -> bus = data_buffer ; // write the data to the output register
223
-
224
- // *** Bit shifting trial - didn't have much improvement in performance
225
- // *output_register = (data_buffer | (((uint32_t) data[i]) << bit_shift));
226
-
227
-
228
216
* set_write = mask ; // set the write pin
229
217
}
230
218
0 commit comments