add driver
This commit is contained in:
0
src/SsdInterface.cpp
Normal file
0
src/SsdInterface.cpp
Normal file
21
src/SsdInterface.hpp
Normal file
21
src/SsdInterface.hpp
Normal file
@@ -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:
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
};
|
||||||
34
src/drivers/ssd.c
Normal file
34
src/drivers/ssd.c
Normal file
@@ -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]);
|
||||||
|
}
|
||||||
|
}
|
||||||
37
src/drivers/ssd.h
Normal file
37
src/drivers/ssd.h
Normal file
@@ -0,0 +1,37 @@
|
|||||||
|
|
||||||
|
#include <stdint.h>
|
||||||
|
#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
|
||||||
|
|
||||||
Reference in New Issue
Block a user