2023-10-26 19:51:20 +02:00
|
|
|
;********************************************************************************
|
|
|
|
; @module SPI
|
|
|
|
; @type driver
|
|
|
|
; @details
|
|
|
|
; @depends IO-W65C22N
|
|
|
|
;********************************************************************************
|
|
|
|
|
2023-10-30 22:14:33 +01:00
|
|
|
.include "system/system.h65"
|
2023-10-26 19:51:20 +02:00
|
|
|
|
|
|
|
.ifndef INCLUDE_SPI
|
|
|
|
INCLUDE_SPI = 1
|
|
|
|
.segment "CODE"
|
|
|
|
|
2023-10-30 22:14:33 +01:00
|
|
|
|
|
|
|
.struct SPI_P_Pins
|
2023-10-26 19:51:20 +02:00
|
|
|
; VIA addresses
|
|
|
|
DDR_a .word ; address of the data direction register
|
|
|
|
R_a .word ; address of the register
|
|
|
|
; pin mask
|
2023-10-30 22:14:33 +01:00
|
|
|
SCLK_p .byte ; Serial Clock
|
2023-10-26 19:51:20 +02:00
|
|
|
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
|
2023-10-30 22:14:33 +01:00
|
|
|
|
|
|
|
;********************************************************************************
|
|
|
|
; @function Initialize the IO Adapter for SPI
|
|
|
|
; @param ARG0-1 Address of the SPI_Pins struct
|
|
|
|
;********************************************************************************
|
|
|
|
.proc spi_p_init
|
|
|
|
; todo USE MASKS
|
|
|
|
; set Shift register to shift in under external clock on CB1
|
|
|
|
lda #%00001100
|
|
|
|
sta SPI_IO + IO_ACR
|
|
|
|
|
|
|
|
; enable SR interrupts
|
|
|
|
lda #%10000100
|
|
|
|
sta SPI_IO + IO_IER
|
|
|
|
rts
|
|
|
|
.endproc
|
|
|
|
|
|
|
|
.proc spi_p_read
|
|
|
|
; print received byte
|
|
|
|
lda SPI_IO + IO_SR
|
|
|
|
jsr _lcd_char
|
|
|
|
rts
|
|
|
|
.endproc
|
|
|
|
|
2023-10-26 19:51:20 +02:00
|
|
|
|
2023-10-30 22:14:33 +01:00
|
|
|
;********************************************************************************
|
|
|
|
; @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
|
2023-10-26 19:51:20 +02:00
|
|
|
;********************************************************************************
|
|
|
|
; @function Send bytes
|
|
|
|
; @param X Number of bytes to send
|
2023-10-30 22:14:33 +01:00
|
|
|
; @param ARG0-1 Address of the SPI_Pins struct
|
|
|
|
; @param ARG2-3 Address of the first byte
|
2023-10-26 19:51:20 +02:00
|
|
|
;********************************************************************************
|
2023-10-30 22:14:33 +01:00
|
|
|
.proc send_data
|
|
|
|
.endproc
|
2023-10-26 19:51:20 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
_send_byte:
|
|
|
|
|
|
|
|
.endif
|