Skip to content

Commit

Permalink
POST code output to the LEDs
Browse files Browse the repository at this point in the history
  • Loading branch information
MrGreensWorkshop committed Jun 8, 2023
1 parent fa33195 commit cd611be
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 2 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ I usually use old or junk parts on my projects to reduce electronic waste and su

- LPC bus sniffer
- POST code output to USB CDC
- POST code output to the LEDs

### Compilation

Expand Down
17 changes: 16 additions & 1 deletion src/lpc_bus_sniffer.pio
Original file line number Diff line number Diff line change
Expand Up @@ -33,28 +33,37 @@ in pins, 4 ; Get the DATA[1].
wait 1 pin 4 ; Wait until the LCLK pin goes high.

in null, 24 ; Shift the ISR 24 bit to get DATA.
mov OSR, ~ISR ; Invert ISR and copy to OSR.
out pins, 8 ; Output the DATA to the LEDs.
push ; Push to get the DATA value on terminal.
.wrap

% c-sdk {

//#define SIDE_PIN 26 // For debugging

void lpc_bus_sniffer_program_init(PIO pio, uint sm, uint offset, uint lpc_bus_pin_base) {
void lpc_bus_sniffer_program_init(PIO pio, uint sm, uint offset, uint lpc_bus_pin_base, uint led_pin_base) {
pio_sm_config c = lpc_bus_sniffer_program_get_default_config(offset);

// Connect the GPIOs to selected PIO block
for(uint i = lpc_bus_pin_base; i < lpc_bus_pin_base + 6; i++) {
pio_gpio_init(pio, i);
}

for(uint i = led_pin_base; i < led_pin_base + 8; i++) {
pio_gpio_init(pio, i);
}

#ifdef SIDE_PIN
pio_gpio_init(pio, SIDE_PIN);
#endif

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

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

#ifdef SIDE_PIN
// Set the selected pin direction for the selected 1 pin. SIDE_PIN (true: out)
pio_sm_set_consecutive_pindirs(pio, sm, SIDE_PIN, 1, true );
Expand All @@ -77,11 +86,17 @@ void lpc_bus_sniffer_program_init(PIO pio, uint sm, uint offset, uint lpc_bus_pi
// Set 'IN' base pin. To read the LAD[0-3].
sm_config_set_in_pins(&c, lpc_bus_pin_base);

// Set 'OUT' base pin. To drive the LED's.
sm_config_set_out_pins(&c, led_pin_base, 8);

#ifdef SIDE_PIN
// Set 'SIDESET' base pin. It's for debugging.
sm_config_set_sideset_pins(&c, SIDE_PIN);
#endif

// Set output pins to high (led's are common anode)
pio_sm_set_pins_with_mask(pio, sm, 0xffu << led_pin_base, 0xffu << led_pin_base);

pio_sm_init(pio, sm, offset, &c);
}

Expand Down
14 changes: 13 additions & 1 deletion src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
// Set the system frequency to 33 MHz x 6 to make time for handling LPC frames.
#define SYS_FREQ_IN_KHZ (198 * 1000)

// POST Code LEDs[0–8], which start from GPIO8.
#define LED_POST_CODE_PIN_BASE (8U)

#define LED_STATUS_PIN PICO_DEFAULT_LED_PIN
#define INTERVAL_IM_ALIVE_MS (1000)

Expand All @@ -17,6 +20,15 @@ void gpio_initialization() {

// Set the Status LED GPIO pin as output.
gpio_set_dir(LED_STATUS_PIN, GPIO_OUT);

// Init the POST Code LED pins.
gpio_init_mask(0xffu << LED_POST_CODE_PIN_BASE);

// Set the POST Code LED pins to high. (led's are common anode)
gpio_set_mask(0xffu << LED_POST_CODE_PIN_BASE);

// Set the POST Code LED pins as output.
gpio_set_dir_out_masked(0xffu << LED_POST_CODE_PIN_BASE);
}

void flash_led_once(void) {
Expand Down Expand Up @@ -47,7 +59,7 @@ int init_lpc_bus_sniffer(PIO pio) {
return -2;
}

lpc_bus_sniffer_program_init(pio, sm, offset, lpc_bus_pin_base);
lpc_bus_sniffer_program_init(pio, sm, offset, lpc_bus_pin_base, LED_POST_CODE_PIN_BASE);
pio_sm_set_enabled(pio, sm, true);

// To sniff the POST codes
Expand Down

0 comments on commit cd611be

Please sign in to comment.