84 lines
2.2 KiB
Plaintext
84 lines
2.2 KiB
Plaintext
;********************************************************************************
|
|
; @module SPI
|
|
; @type driver
|
|
; @details
|
|
; @depends IO-W65C22N
|
|
;********************************************************************************
|
|
|
|
.include "system/system.h65"
|
|
|
|
.ifndef INCLUDE_SPI
|
|
INCLUDE_SPI = 1
|
|
.segment "CODE"
|
|
|
|
SPI_CODE_START = $3000
|
|
SPI_PAGES_WRITTEN = $2fff
|
|
SPI_BYTES_WRITTEN = $2ffe
|
|
|
|
|
|
.struct SPI_P_Pins
|
|
; VIA addresses
|
|
DDR_a .word ; address of the data direction register
|
|
R_a .word ; address of the register
|
|
; pin mask
|
|
SCLK_p .byte ; Serial Clock
|
|
POCI_p .byte ; Peripheral Out / Controller In
|
|
PICO_p .byte ; Peripheral In / Controller Out
|
|
CSB_p .byte ; Chip Select
|
|
; settings
|
|
CPOL .byte ; Clock Polarity
|
|
CPHA .byte ; Clock Phase
|
|
.endstruct
|
|
|
|
;********************************************************************************
|
|
; @function Initialize the IO Adapter for SPI
|
|
; @param ARG0-1 Address of the SPI_Pins struct
|
|
;********************************************************************************
|
|
.proc spi_p_init
|
|
stz SPI_PAGES_WRITTEN
|
|
stz SPI_BYTES_WRITTEN
|
|
; todo USE MASKS
|
|
; set Shift register to shift in under external clock on CB1
|
|
lda #IO::ACR::SR_SIN_PHIE
|
|
sta SPI_IO + IO::ACR
|
|
|
|
; enable SR interrupts
|
|
lda #(IO::IRQ::IRQ | IO::IRQ::SR)
|
|
sta SPI_IO + IO::IER
|
|
DEBUG_LED_ON 1
|
|
rts
|
|
.endproc
|
|
|
|
.proc spi_p_read
|
|
DEBUG_LED_ON 0
|
|
; print received byte
|
|
lda SPI_IO + IO::SR
|
|
jsr lcd_char
|
|
inc SPI_BYTES_WRITTEN
|
|
rts
|
|
.endproc
|
|
|
|
|
|
;********************************************************************************
|
|
; @function Read bytes
|
|
; @param X Number of bytes to send
|
|
; @param ARG0-1 Address of the SPI_Pins struct
|
|
; @param ARG2-3 Address of the first byte
|
|
;********************************************************************************
|
|
.proc recv_data
|
|
.endproc
|
|
;********************************************************************************
|
|
; @function Send bytes
|
|
; @param X Number of bytes to send
|
|
; @param ARG0-1 Address of the SPI_Pins struct
|
|
; @param ARG2-3 Address of the first byte
|
|
;********************************************************************************
|
|
.proc send_data
|
|
.endproc
|
|
|
|
|
|
|
|
_send_byte:
|
|
|
|
.endif
|