@@ -21,12 +21,15 @@ static dedic_gpio_bundle_handle_t gpio_in_bundle;
21
21
static dedic_gpio_bundle_handle_t gpio_out_bundle ;
22
22
23
23
/* mask values depends on the location in the gpio bundle array */
24
+ #define GPIO_TDO_MASK 0x01 /* input */
25
+
26
+ /* outputs */
24
27
#define GPIO_TCK_MASK 0x01
25
- #define GPIO_TDO_MASK 0x01
26
28
#define GPIO_TDI_MASK 0x02
27
29
#define GPIO_TMS_MASK 0x04
28
30
#define GPIO_TRST_MASK 0x08
29
31
#define GPIO_SRST_MASK 0x10
32
+ #define GPIO_BLINK_MASK 0x20
30
33
31
34
/* GPIO setup functions */
32
35
static inline void gpio_mode_input_set (int g )
@@ -52,6 +55,7 @@ static inline void gpio_clear(int g)
52
55
static bb_value_t esp32_gpio_read (void );
53
56
static int esp32_gpio_write (int tck , int tms , int tdi );
54
57
static int esp32_gpio_reset (int trst , int srst );
58
+ static int esp32_gpio_blink (int on );
55
59
56
60
static int esp32_gpio_init (void );
57
61
static int esp32_gpio_quit (void );
@@ -64,24 +68,21 @@ static struct bitbang_interface esp32_gpio_bitbang = {
64
68
.blink = NULL
65
69
};
66
70
67
- /* GPIO numbers for each signal. Negative values are invalid */
68
- static int tck_gpio = -1 ;
69
- static int tms_gpio = -1 ;
70
- static int tdi_gpio = -1 ;
71
- static int tdo_gpio = -1 ;
72
- static int trst_gpio = -1 ;
73
- static int srst_gpio = -1 ;
74
-
75
- /* Transition delay coefficients. Tuned for IMX6UL 528MHz. Adjusted
76
- * experimentally for:10kHz, 100Khz, 500KHz. Speeds above 800Khz are impossible
77
- * to reach via memory mapped method (at least for IMX6UL@528MHz).
78
- * Measured mmap raw GPIO toggling speed on IMX6UL@528MHz: 1.3MHz.
79
- */
71
+ /* GPIO default values for each pin */
72
+ static int tck_gpio = GPIO_NUM_NC ;
73
+ static int tms_gpio = GPIO_NUM_NC ;
74
+ static int tdi_gpio = GPIO_NUM_NC ;
75
+ static int tdo_gpio = GPIO_NUM_NC ;
76
+ static int trst_gpio = GPIO_NUM_NC ;
77
+ static int srst_gpio = GPIO_NUM_NC ;
78
+ static int blink_gpio = GPIO_NUM_NC ;
79
+
80
80
static unsigned int jtag_delay = 0 ;
81
81
82
82
static bb_value_t esp32_gpio_read (void )
83
83
{
84
- return dedic_gpio_cpu_ll_read_in () & GPIO_TDO_MASK ? BB_HIGH : BB_LOW ;
84
+ /* we have only one input and it's mask value is 0x01. So we don't need to check the mask value. */
85
+ return dedic_gpio_cpu_ll_read_in ();
85
86
}
86
87
87
88
static int esp32_gpio_write (int tck , int tms , int tdi )
@@ -96,13 +97,19 @@ static int esp32_gpio_write(int tck, int tms, int tdi)
96
97
return ERROR_OK ;
97
98
}
98
99
100
+ static int esp32_gpio_blink (int on )
101
+ {
102
+ dedic_gpio_cpu_ll_write_mask (GPIO_BLINK_MASK , on ? GPIO_BLINK_MASK : 0 );
103
+ return ERROR_OK ;
104
+ }
105
+
99
106
/* (1) assert or (0) deassert reset lines */
100
107
static int esp32_gpio_reset (int trst , int srst )
101
108
{
102
- if (trst_gpio != -1 )
109
+ if (trst_gpio != GPIO_NUM_NC )
103
110
dedic_gpio_cpu_ll_write_mask (GPIO_TRST_MASK , trst ? GPIO_TRST_MASK : 0 );
104
111
105
- if (srst_gpio != -1 )
112
+ if (srst_gpio != GPIO_NUM_NC )
106
113
dedic_gpio_cpu_ll_write_mask (GPIO_SRST_MASK , srst ? GPIO_SRST_MASK : 0 );
107
114
108
115
return ERROR_OK ;
@@ -205,6 +212,15 @@ COMMAND_HANDLER(esp32_gpio_handle_jtag_gpionum_trst)
205
212
return ERROR_OK ;
206
213
}
207
214
215
+ COMMAND_HANDLER (esp32_gpio_handle_jtag_gpionum_blink )
216
+ {
217
+ if (CMD_ARGC == 1 )
218
+ COMMAND_PARSE_NUMBER (int , CMD_ARGV [0 ], blink_gpio );
219
+
220
+ command_print (CMD , "esp32_gpio GPIO config: blink = %d" , blink_gpio );
221
+ return ERROR_OK ;
222
+ }
223
+
208
224
static const struct command_registration esp32_gpio_command_handlers [] = {
209
225
{
210
226
.name = "esp32_gpio_jtag_nums" ,
@@ -255,6 +271,13 @@ static const struct command_registration esp32_gpio_command_handlers[] = {
255
271
.help = "gpio number for trst." ,
256
272
.usage = "[trst]" ,
257
273
},
274
+ {
275
+ .name = "esp32_gpio_blink_num" ,
276
+ .handler = & esp32_gpio_handle_jtag_gpionum_blink ,
277
+ .mode = COMMAND_CONFIG ,
278
+ .help = "gpio number for blink." ,
279
+ .usage = "[blink]" ,
280
+ },
258
281
259
282
COMMAND_REGISTRATION_DONE
260
283
};
@@ -295,12 +318,11 @@ static bool esp32_gpio_jtag_mode_possible(void)
295
318
296
319
static int esp32_gpio_init (void )
297
320
{
298
- bitbang_interface = & esp32_gpio_bitbang ;
299
-
300
321
LOG_INFO ("esp32_gpio GPIO JTAG bitbang driver" );
301
322
302
323
int khz = 5000 ;
303
324
int jtag_speed = 0 ;
325
+
304
326
esp32_gpio_khz (khz , & jtag_speed );
305
327
306
328
/*
@@ -311,7 +333,6 @@ static int esp32_gpio_init(void)
311
333
gpio_clear (tdi_gpio );
312
334
gpio_clear (tck_gpio );
313
335
gpio_set (tms_gpio );
314
-
315
336
gpio_mode_input_set (tdo_gpio );
316
337
gpio_mode_output_set (tdi_gpio );
317
338
gpio_mode_output_set (tck_gpio );
@@ -321,19 +342,25 @@ static int esp32_gpio_init(void)
321
342
return ERROR_FAIL ;
322
343
}
323
344
324
- int bundle_out_gpios [] = { tck_gpio , tdi_gpio , tms_gpio , 0 , 0 };
345
+ int bundle_out_gpios [] = { tck_gpio , tdi_gpio , tms_gpio , 0 , 0 , 0 };
325
346
int bundle_in_gpios [] = { tdo_gpio };
326
347
327
- if (trst_gpio != -1 ) {
348
+ if (trst_gpio != GPIO_NUM_NC ) {
328
349
gpio_set (trst_gpio );
329
350
gpio_mode_output_set (trst_gpio );
330
351
bundle_out_gpios [3 ] = trst_gpio ;
331
352
}
332
- if (srst_gpio != -1 ) {
353
+ if (srst_gpio != GPIO_NUM_NC ) {
333
354
gpio_set (srst_gpio );
334
355
gpio_mode_output_set (srst_gpio );
335
356
bundle_out_gpios [4 ] = srst_gpio ;
336
357
}
358
+ if (blink_gpio != GPIO_NUM_NC ) {
359
+ gpio_clear (blink_gpio );
360
+ gpio_mode_output_set (blink_gpio );
361
+ bundle_out_gpios [5 ] = blink_gpio ;
362
+ esp32_gpio_bitbang .blink = esp32_gpio_blink ;
363
+ }
337
364
338
365
dedic_gpio_bundle_config_t out_bundle_config = {
339
366
.gpio_array = bundle_out_gpios ,
@@ -354,6 +381,8 @@ static int esp32_gpio_init(void)
354
381
dedic_gpio_new_bundle (& out_bundle_config , & gpio_out_bundle );
355
382
dedic_gpio_new_bundle (& in_bundle_config , & gpio_in_bundle );
356
383
384
+ bitbang_interface = & esp32_gpio_bitbang ;
385
+
357
386
return ERROR_OK ;
358
387
}
359
388
0 commit comments