mirror of
https://github.com/sergeyyarkov/pdsp188x.git
synced 2026-10-11 02:18:52 +03:00
41 lines
1.1 KiB
C
41 lines
1.1 KiB
C
#include "avr.h"
|
|
|
|
#include "../../config_avr.h"
|
|
|
|
static void SetPins(uint8_t mask, uint8_t pin_mask, uint8_t state) {
|
|
if (state && mask == PDSP188x_DATA_LINE_MASK) DATA_PORT |= pin_mask;
|
|
if (state && mask == PDSP188x_ADDR_LINE_MASK) ADDR_PORT |= pin_mask;
|
|
if (!state && mask == PDSP188x_DATA_LINE_MASK) DATA_PORT &= ~pin_mask;
|
|
if (!state && mask == PDSP188x_ADDR_LINE_MASK) ADDR_PORT &= ~pin_mask;
|
|
}
|
|
|
|
static void Init(void) {
|
|
DATA_DIR |= WR | FL | CLK | DATA | LATCH | RST;
|
|
ADDR_DIR |= A0 | A1 | A2 | A3 | A4;
|
|
DATA_PORT |= FL | RST;
|
|
SPCR |= _BV(SPE) | _BV(MSTR) | _BV(SPR1) | _BV(SPR0);
|
|
|
|
_delay_ms(10);
|
|
|
|
/* reset */
|
|
DATA_PORT |= _BV(WR) | _BV(FL);
|
|
DATA_PORT &= ~_BV(RST);
|
|
_delay_us(1);
|
|
DATA_PORT |= _BV(RST);
|
|
|
|
_delay_ms(1);
|
|
|
|
DATA_PORT |= WR;
|
|
}
|
|
|
|
static void SendByte(uint8_t byte) {
|
|
SPDR = byte;
|
|
loop_until_bit_is_set(SPSR, SPIF);
|
|
_delay_us(5);
|
|
DATA_PORT |= LATCH;
|
|
_delay_us(5);
|
|
DATA_PORT &= ~LATCH;
|
|
_delay_us(5);
|
|
}
|
|
|
|
const PDSP188x_DriverInterface_t PDSP188x_AVR_Driver = {.init = Init, .send_byte = SendByte, .set_pins = SetPins}; |