ether2ser 0.1.0
Ethernet <-> synchronous V.24 bridge firmware for RP2040 + W5500
Loading...
Searching...
No Matches
blink_pio.c
Go to the documentation of this file.
1/*
2 * ether2ser — Ethernet ↔ synchronous V.24 (RS-232/V.28) bridge
3 *
4 * File: src/examples/blink/blink_pio.c
5 * Purpose: PIO helper to drive a GPIO blink state machine for the example.
6 *
7 * SPDX-License-Identifier: Apache-2.0
8 *
9 * Copyright (c) 2026 Florian <f.leuze@outlook.de>
10 */
11
12// Related headers
13
14// Standard library headers
15
16// Project Headers
17#include "hardware/pio.h"
18#include "pico/types.h"
19
20// Generated headers
21#include "led_blink.pio.h"
22
23void start_pio_led_blink(PIO pio, uint sm, uint pin)
24{
25 // Load PIO program
26 uint offset = pio_add_program(pio, &led_blink_program);
27
28 // Route GPIO to PIO
29 pio_gpio_init(pio, pin);
30 pio_sm_set_consecutive_pindirs(pio, sm, pin, 1, true);
31
32 // Configure state machine
33 pio_sm_config c = led_blink_program_get_default_config(offset);
34 sm_config_set_set_pins(&c, pin, 1);
35
36 // Slow down the state machine clock so blinking is visible.
37 // 125 MHz / 65535 / 64 cycles ≈ 30 Hz toggle rate (15 Hz blink)
38 // For slower: increase delay in PIO program [31] -> larger value
39 sm_config_set_clkdiv(&c, 65535.0f);
40 pio_sm_init(pio, sm, offset, &c);
41 pio_sm_set_enabled(pio, sm, true);
42}