SHR16 gpio

pull/28/head
Alex Voinea 2021-06-04 12:49:50 +03:00 committed by DRracer
parent 58fe013471
commit 7845f9aad4
2 changed files with 20 additions and 25 deletions

View File

@ -1,5 +1,6 @@
#include "../shr16.h"
#include "../gpio.h"
#include "../../pins.h"
namespace hal {
namespace shr16 {
@ -7,34 +8,24 @@ namespace shr16 {
SHR16 shr16;
void SHR16::Init() {
// DDRC |= 0x80;
// DDRB |= 0x40;
// DDRB |= 0x20;
// PORTC &= ~0x80;
// PORTB &= ~0x40;
// PORTB &= ~0x20;
// shr16_v = 0;
// Write(shr16_v);
// Write(shr16_v);
using namespace hal::gpio;
gpio::Init(GPIO_pin(SHR16_DATA), GPIO_InitTypeDef(Mode::output, Level::low));
gpio::Init(GPIO_pin(SHR16_LATCH), GPIO_InitTypeDef(Mode::output, Level::high));
gpio::Init(GPIO_pin(SHR16_CLOCK), GPIO_InitTypeDef(Mode::output, Level::low));
Write(0);
}
void SHR16::Write(uint16_t v) {
// PORTB &= ~0x40;
// asm("nop");
// for (uint16_t m = 0x8000; m; m >>= 1)
// {
// if (m & v)
// PORTB |= 0x20;
// else
// PORTB &= ~0x20;
// PORTC |= 0x80;
// asm("nop");
// PORTC &= ~0x80;
// asm("nop");
// }
// PORTB |= 0x40;
// asm("nop");
// shr16_v = v;
using namespace hal::gpio;
WritePin(GPIO_pin(SHR16_LATCH), Level::low);
for (uint16_t m = 0x8000; m; m >>= 1)
{
WritePin(GPIO_pin(SHR16_DATA), (Level)((m & v) != 0));
WritePin(GPIO_pin(SHR16_CLOCK), Level::high);
WritePin(GPIO_pin(SHR16_CLOCK), Level::low);
}
WritePin(GPIO_pin(SHR16_LATCH), Level::high);
shr16_v = v;
}
void SHR16::SetLED(uint16_t led) {

View File

@ -7,3 +7,7 @@
#define TMC2130_SPI_MOSI_PIN GPIOB, 2
#define TMC2130_SPI_SCK_PIN GPIOB, 1
#define TMC2130_SPI_SS_PIN GPIOB, 0
#define SHR16_DATA GPIOB, 5 ///DS
#define SHR16_LATCH GPIOB, 6 ///STCP
#define SHR16_CLOCK GPIOB, 7 ///SHCP