6502-OS/system/spi.h65

58 lines
1.9 KiB
Plaintext
Raw Normal View History

2023-12-23 14:17:49 +01:00
;;********************************************************************************
2024-08-08 21:11:25 +02:00
;; @file
;; @brief SPI Perpiheral
2023-12-23 14:17:49 +01:00
;; @details
;; Support being a peripheral SPI device.
;; @depends IO-W65C22N
;;********************************************************************************
2023-12-08 22:56:35 +01:00
.ifndef INCLUDE_SPI
INCLUDE_SPI = 1
.include "system/system.h65"
;;********************************************************************************
2024-08-08 20:15:50 +02:00
;; @brief Support being a peripheral SPI device
;; @details
;; This requires the data line to be hooked up to `CB2` and the clock to `CB1`.
;; The VIA will be set to shift in the data into the shift register under the external clock.
2024-08-08 20:39:25 +02:00
;; @ingroup drivers
2024-08-08 20:15:50 +02:00
;; @see via_hardware_bug "VIA external clock bug"
;;********************************************************************************
2023-12-08 22:56:35 +01:00
.scope spi_p
2024-08-08 20:15:50 +02:00
;; Address of the VIA that is used for the spi connection
2023-12-08 22:56:35 +01:00
SPI_IO = IO2
2023-12-31 01:58:47 +01:00
Import spi_p, init, irq_handler, status, buffer_size, recv_size
ImportZp spi_p, buffer_ptr
Import spi_p, begin_read, end_read, irq_read_byte, recv_bytes
Import spi_p, begin_write, end_write, irq_write_byte, sent_bytes
2023-12-23 14:17:49 +01:00
;;********************************************************************************
;; @brief Status of a SPI transfer
;;********************************************************************************
2023-12-23 14:17:49 +01:00
.enum STATUS
XFER_SIZEL = %10000000
XFER_SIZEH = %01000000
XFER = %00000001
DONE = %00000000
2023-12-31 01:58:47 +01:00
ERROR = %00100000
2023-12-23 14:17:49 +01:00
.endenum
2023-12-08 22:56:35 +01:00
.endscope
.endif ; guard
2023-12-27 16:56:14 +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