mirror of
https://github.com/sergeyyarkov/pdsp188x.git
synced 2026-10-11 18:38:53 +03:00
54 lines
1.2 KiB
C
54 lines
1.2 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 |= WR | FL;
|
|
DATA_PORT &= ~RST;
|
|
_delay_us(1);
|
|
DATA_PORT |= 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);
|
|
}
|
|
|
|
static void DelayMS(uint8_t ms) {
|
|
while (ms--) {
|
|
_delay_ms(1);
|
|
}
|
|
}
|
|
|
|
static void DelayUS(uint8_t us) {
|
|
while (us--) {
|
|
_delay_us(1);
|
|
}
|
|
}
|
|
|
|
const PDSP188x_DriverInterface_t PDSP188x_AVR_Driver = {
|
|
.init = Init, .send_byte = SendByte, .set_pins = SetPins, .delay_ms = DelayMS, .delay_us = DelayUS}; |