TPIC6B595
An embedded-hal driver for the TPIC6B595 Shift Register
This crate provides an embedded-hal compatible driver for the TPIC6B595 power shift register. It supports daisy-chaining multiple devices to expand output capabilities. The driver is designed for no_std environments, making it suitable for bare-metal embedded applications.
Features
no_stdcompatible.- Uses
embedded-halv1.0 traits for SPI, OutputPin, and DelayNs. - Supports daisy-chaining multiple TPIC6B595 devices (parameterized by
N). - Functions for setting and getting individual output states by index.
- Ability to clear all outputs.
- Global Output Enable via (
/G) pin. - Handles internal data buffering and SPI communication.
Limitation
- takes ownership of the SPI Device, so no bus sharing possible at the moment
Connections
SPI_MOSI: Connect to TPIC6B595SER IN(Serial Data Input).SPI_CLK: Connect to TPIC6B595SRCLK(Shift Register Clock).LATCHpin: Connect to TPIC6B595RCK(Storage Register Clock). This pin is pulsed high-low to transfer the shift register contents to the storage register (outputs)./OE(Output Enable) pin: Connect to TPIC6B595/G. Active low; pull low to enable outputs, high to disable./SRCLR: This driver does not use the/SRCLRpin. It should be tied to VCC on your hardware. Clearing is performed by shifting all zeroes through the SPI interface.
Note on Data Ordering
When daisy-chaining, the internal data buffer data: [u8; N] in the ShiftRegister struct expects data such that data[N-1] corresponds to the first shift register in the chain (closest to the SER IN input), data[N-2] to the second, and so on, with data[0] being the last shift register in the chain. The set_output and get_output methods handle this ordering automatically based on a single linear index 0 to (N*8)-1.
data[N-1] data[N-2] ... data[0]
┌────────────────┌────────────────┌────────────────┐
│ SR 1 │ SR 2 │ SR N │
│0 1 2 3 4 5 6 7 │0 1 2 3 4 5 6 7 │0 1 2 3 4 5 6 7 │
└────────────────└────────────────└────────────────┘
idx 0 1 2 3 4 5 6 7 8 9 ... (N*8)-1
Usage
Add the following to your Cargo.toml dependencies:
# filepath: Cargo.toml
[]
= "0.1.0"
= "1.0"
Example for STM32F4xx:
let p = take.unwrap;
let cp = take.unwrap;
let mut rcc = p
.RCC
.freeze;
let mut systick = cp.SYST.delay;
let gpiod = p.GPIOD.split;
let mut led = gpiod.pd14.into_push_pull_output;
// Shift register resources
let gpioc = p.GPIOC.split;
let not_oe = gpioc.pc6.into_push_pull_output;
let latch = gpioc.pc7.into_push_pull_output;
let delay = p.TIM5.delay_us;
// SPI1 Config
// SCK: PB3 / AF5
// MISO: NOT USED
// MOSI: PB5 / AF5
// CS: PB4
let gpiob = p.GPIOB.split;
let sck = gpiob
.pb3
.
.speed
.internal_pull_up;
let mosi = gpiob
.pb5
.
.speed
.internal_pull_up;
let cs = new_high; // use crate dummy-pin
let mode = Mode ;
let spi_driver = new;
// use crate embedded_hal_bus for SpiDevice trait
let spi_device = new_no_delay.unwrap;
// Create the ShiftRegister (2 daisy chained devices)
let mut shift_register = new;
// Only set internal state
shift_register.set_output;
shift_register.set_output;
// Write to device
if shift_register.write_output.is_err