2023-10-26 19:51:20 +02:00
|
|
|
;********************************************************************************
|
|
|
|
; @module SPI
|
|
|
|
; @type driver
|
|
|
|
; @details
|
|
|
|
; @depends IO-W65C22N
|
|
|
|
;********************************************************************************
|
|
|
|
|
2023-11-11 12:13:47 +01:00
|
|
|
.include "system/system.s65"
|
2023-11-13 19:14:39 +01:00
|
|
|
.include "programs/print_slow.s65"
|
2023-10-26 19:51:20 +02:00
|
|
|
|
|
|
|
.ifndef INCLUDE_SPI
|
|
|
|
INCLUDE_SPI = 1
|
|
|
|
|
2023-10-30 22:14:33 +01:00
|
|
|
|
2023-11-11 12:13:47 +01:00
|
|
|
.bss
|
|
|
|
SPI_PAGES_WRITTEN: .res 1
|
|
|
|
SPI_BYTES_WRITTEN: .res 1
|
2023-11-13 19:14:39 +01:00
|
|
|
.segment "SPI"
|
|
|
|
SPI_CODE_START: ; .res $1000
|
|
|
|
lda $1000
|
|
|
|
sta $1000
|
|
|
|
lda $1000
|
|
|
|
sta $1000
|
|
|
|
lda $1000
|
|
|
|
sta $1000
|
|
|
|
lda IO1 + IO::RA
|
|
|
|
lda IO1 + IO::RA
|
|
|
|
bra SPI_CODE_START
|
|
|
|
; jsr lcd_clear
|
|
|
|
; PrintSlow msg,20
|
|
|
|
; jmp home
|
|
|
|
; msg:
|
|
|
|
; .asciiz "YO DAS WAR SPI"
|
|
|
|
|
|
|
|
|
2023-11-09 12:10:00 +01:00
|
|
|
|
2023-11-11 12:13:47 +01:00
|
|
|
.code
|
2023-11-09 12:10:00 +01:00
|
|
|
.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
|
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
|
2023-11-09 12:10:00 +01:00
|
|
|
stz SPI_PAGES_WRITTEN
|
|
|
|
stz SPI_BYTES_WRITTEN
|
2023-10-30 22:14:33 +01:00
|
|
|
; todo USE MASKS
|
|
|
|
; set Shift register to shift in under external clock on CB1
|
2023-11-01 13:13:23 +01:00
|
|
|
lda #IO::ACR::SR_SIN_PHIE
|
|
|
|
sta SPI_IO + IO::ACR
|
2023-10-30 22:14:33 +01:00
|
|
|
|
|
|
|
; enable SR interrupts
|
2023-11-01 13:13:23 +01:00
|
|
|
lda #(IO::IRQ::IRQ | IO::IRQ::SR)
|
|
|
|
sta SPI_IO + IO::IER
|
2023-11-09 12:10:00 +01:00
|
|
|
DEBUG_LED_ON 1
|
2023-10-30 22:14:33 +01:00
|
|
|
rts
|
|
|
|
.endproc
|
|
|
|
|
|
|
|
.proc spi_p_read
|
2023-11-09 12:10:00 +01:00
|
|
|
DEBUG_LED_ON 0
|
2023-10-30 22:14:33 +01:00
|
|
|
; print received byte
|
2023-11-01 13:13:23 +01:00
|
|
|
lda SPI_IO + IO::SR
|
2023-11-13 19:14:39 +01:00
|
|
|
sta SPI_CODE_START,x
|
2023-11-09 12:10:00 +01:00
|
|
|
inc SPI_BYTES_WRITTEN
|
2023-11-13 19:14:39 +01:00
|
|
|
jsr lcd_char
|
2023-10-30 22:14:33 +01:00
|
|
|
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
|