Skip to content

Commit 3f5b0ad

Browse files
Defining pin bases and counts. (Refactoring)
1 parent f04b052 commit 3f5b0ad

File tree

3 files changed

+13
-9
lines changed

3 files changed

+13
-9
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ I usually use old or junk parts on my projects to reduce electronic waste and su
3333
- POST code output to the LEDs
3434
- Filter LPC I/0 frame with start, cycle/dir and address
3535
- Abort frame support
36+
- Defining pin bases and counts (Refactoring)
3637

3738
### Compilation
3839

src/lpc_bus_sniffer.pio

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -56,15 +56,15 @@ push ; Push to get the DATA value on terminal.
5656

5757
//#define SIDE_PIN 26 // For debugging
5858

59-
void lpc_bus_sniffer_program_init(PIO pio, uint sm, uint offset, uint lpc_bus_pin_base, uint led_pin_base) {
59+
void lpc_bus_sniffer_program_init(PIO pio, uint sm, uint offset, uint lpc_bus_pin_base, uint lpc_bus_pin_count, uint led_pin_base, uint led_pin_count) {
6060
pio_sm_config c = lpc_bus_sniffer_program_get_default_config(offset);
6161

6262
// Connect the GPIOs to selected PIO block
63-
for(uint i = lpc_bus_pin_base; i < lpc_bus_pin_base + 6; i++) {
63+
for(uint i = lpc_bus_pin_base; i < lpc_bus_pin_base + lpc_bus_pin_count; i++) {
6464
pio_gpio_init(pio, i);
6565
}
6666

67-
for(uint i = led_pin_base; i < led_pin_base + 8; i++) {
67+
for(uint i = led_pin_base; i < led_pin_base + led_pin_count; i++) {
6868
pio_gpio_init(pio, i);
6969
}
7070

@@ -73,10 +73,10 @@ void lpc_bus_sniffer_program_init(PIO pio, uint sm, uint offset, uint lpc_bus_pi
7373
#endif
7474

7575
// Set the selected pin directions for the selected 6 pins. LAD[0-3] + LCLK + LFRAME (false: in)
76-
pio_sm_set_consecutive_pindirs(pio, sm, lpc_bus_pin_base, 6, false);
76+
pio_sm_set_consecutive_pindirs(pio, sm, lpc_bus_pin_base, lpc_bus_pin_count, false);
7777

7878
// Set the selected pin directions for the selected 8 pins. LED[0-8] (true: out)
79-
pio_sm_set_consecutive_pindirs(pio, sm, led_pin_base, 8, true);
79+
pio_sm_set_consecutive_pindirs(pio, sm, led_pin_base, led_pin_count, true);
8080

8181
#ifdef SIDE_PIN
8282
// Set the selected pin direction for the selected 1 pin. SIDE_PIN (true: out)
@@ -101,7 +101,7 @@ void lpc_bus_sniffer_program_init(PIO pio, uint sm, uint offset, uint lpc_bus_pi
101101
sm_config_set_in_pins(&c, lpc_bus_pin_base);
102102

103103
// Set 'OUT' base pin. To drive the LED's.
104-
sm_config_set_out_pins(&c, led_pin_base, 8);
104+
sm_config_set_out_pins(&c, led_pin_base, led_pin_count);
105105

106106
// Set 'JMP' pin. To read the LFRAME.
107107
sm_config_set_jmp_pin(&c, lpc_bus_pin_base + 5);

src/main.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,13 @@
88
// Set the system frequency to 33 MHz x 6 to make time for handling LPC frames.
99
#define SYS_FREQ_IN_KHZ (198 * 1000)
1010

11+
// LAD[0-3] + LCLK + LFRAME, which starts from GPIO0.
12+
#define LPC_BUS_PIN_BASE (0U)
13+
#define LPC_BUS_PIN_COUNT (6U)
14+
1115
// POST Code LEDs[0–8], which start from GPIO8.
1216
#define LED_POST_CODE_PIN_BASE (8U)
17+
#define LED_POST_CODE_PIN_COUNT (8U)
1318

1419
#define LED_STATUS_PIN PICO_DEFAULT_LED_PIN
1520
#define INTERVAL_IM_ALIVE_MS (1000)
@@ -60,8 +65,6 @@ uint32_t reverse_nibbles(uint32_t in_val) {
6065
}
6166

6267
int init_lpc_bus_sniffer(PIO pio) {
63-
// LAD[0-3] + LCLK + LFRAME which starts from GPIO0
64-
uint lpc_bus_pin_base = 0;
6568
uint offset;
6669

6770
printf("initializing the lpc bus sniffer program\n");
@@ -79,7 +82,7 @@ int init_lpc_bus_sniffer(PIO pio) {
7982
return -2;
8083
}
8184

82-
lpc_bus_sniffer_program_init(pio, sm, offset, lpc_bus_pin_base, LED_POST_CODE_PIN_BASE);
85+
lpc_bus_sniffer_program_init(pio, sm, offset, LPC_BUS_PIN_BASE, LPC_BUS_PIN_COUNT, LED_POST_CODE_PIN_BASE, LED_POST_CODE_PIN_COUNT);
8386
pio_sm_set_enabled(pio, sm, true);
8487

8588
// Set the I/O RW frame filter

0 commit comments

Comments
 (0)