From 8e9d459345ea2b33041b8370defadc8385288b89 Mon Sep 17 00:00:00 2001 From: Blitblank Date: Sun, 7 Dec 2025 18:20:08 -0600 Subject: [PATCH] add driver --- src/SsdInterface.cpp | 0 src/SsdInterface.hpp | 21 +++++++++++++++++++++ src/drivers/ssd.c | 34 ++++++++++++++++++++++++++++++++++ src/drivers/ssd.h | 37 +++++++++++++++++++++++++++++++++++++ 4 files changed, 92 insertions(+) create mode 100644 src/SsdInterface.cpp create mode 100644 src/SsdInterface.hpp create mode 100644 src/drivers/ssd.c create mode 100644 src/drivers/ssd.h diff --git a/src/SsdInterface.cpp b/src/SsdInterface.cpp new file mode 100644 index 0000000..e69de29 diff --git a/src/SsdInterface.hpp b/src/SsdInterface.hpp new file mode 100644 index 0000000..f7e690f --- /dev/null +++ b/src/SsdInterface.hpp @@ -0,0 +1,21 @@ + +#pragma once + +#include "drivers/ssd.h" +#include "stdint.h" + +class SsdInterface { + +public: + + SsdInterface(); + ~SsdInterface() = default; + + uint32_t write(int32_t value, bool hex); // hex=false => decimal + uint32_t write(int32_t value, uint32_t decimal); + +private: + + + +}; diff --git a/src/drivers/ssd.c b/src/drivers/ssd.c new file mode 100644 index 0000000..079126a --- /dev/null +++ b/src/drivers/ssd.c @@ -0,0 +1,34 @@ + +#include "ssd.h" + +void shiftInit(const ssd_595_t* device) { + gpio_config_t ioConfig = { + .mode = GPIO_MODE_OUTPUT, + .pin_bit_mask = (1ULL << device->dataPin) | + (1ULL << device->clockPin) | + (1ULL << device->latchPin) + }; + gpio_config(&ioConfig); + + gpio_set_level(device->dataPin, 0); + gpio_set_level(device->clockPin, 0); + gpio_set_level(device->latchPin, 0); +} + +void addDecimal(uint8_t* data) { + data = (*data | 0x01); +} + +void shiftByte(const ssd_595_t* device, uint8_t byte) { + for(int i = 0; i < __CHAR_BIT__; i++) { + gpio_set_level(device->dataPin, (byte >> i) & 0x1); + pulse(device->clockPin); + } + pulse(device->latchPin); +} + +void shiftBytes(const ssd_595_t* device, uint8_t* bytes, size_t numBytes) { + for(size_t i = 0; i < numBytes; i++) { + shiftByte(device, bytes[i]); + } +} \ No newline at end of file diff --git a/src/drivers/ssd.h b/src/drivers/ssd.h new file mode 100644 index 0000000..f553084 --- /dev/null +++ b/src/drivers/ssd.h @@ -0,0 +1,37 @@ + +#include +#include "driver/gpio.h" + +typedef struct { + gpio_num_t dataPin; + gpio_num_t clockPin; + gpio_num_t latchPin; +} ssd_595_t; + +uint8_t map[17] = { // encoding of digits on the seven segment display + 0xFC, // 0 + 0x60, // 1 + 0xDA, // 2 + 0xF2, // 3 + 0x66, // 4 + 0xB6, // 5 + 0xBE, // 6 + 0xE0, // 7 + 0xFE, // 8 + 0xF6, // 9 + 0xEE, // A + 0x3E, // B + 0x9C, // C + 0x7A, // D + 0x9E, // E + 0x8E, // F + 0x02, // - +}; + +void shiftInit(const ssd_595_t* device); + +void addDecimal(uint8_t* data); // adds a decimal to a single digit + +void shiftByte(const ssd_595_t* device, uint8_t byte); // outputs a serial byte, big-endian +void shiftBytes(const ssd_595_t* device, uint8_t* bytes, size_t numBytes); // outputs multiple bytes +