Update spi.s
Use names instead of magic values.
This commit is contained in:
10
sw/spi.s
10
sw/spi.s
@@ -7,6 +7,10 @@
|
|||||||
|
|
||||||
.code
|
.code
|
||||||
|
|
||||||
|
SPI_SCLK = $01
|
||||||
|
SPI_SSn = $02
|
||||||
|
SPI_MOSI = $04
|
||||||
|
|
||||||
|
|
||||||
; Write a single byte to the SPI device
|
; Write a single byte to the SPI device
|
||||||
; @in A The byte to write
|
; @in A The byte to write
|
||||||
@@ -19,16 +23,18 @@ _spi_write_byte:
|
|||||||
tax
|
tax
|
||||||
@loop: bit tmp1 ; Check if high bit set
|
@loop: bit tmp1 ; Check if high bit set
|
||||||
beq @1
|
beq @1
|
||||||
lda #$04 ; Bit not set.
|
lda #SPI_MOSI ; Bit not set.
|
||||||
bra @1
|
bra @1
|
||||||
@1: lda #$00 ; Bit set
|
@1: lda #$00 ; Bit set
|
||||||
sta BB_SPI_BASE ; Write data
|
sta BB_SPI_BASE ; Write data
|
||||||
adc #$01
|
adc #SPI_SCLK
|
||||||
sta BB_SPI_BASE ; Write clock
|
sta BB_SPI_BASE ; Write clock
|
||||||
txa
|
txa
|
||||||
lsr ; Select next bit
|
lsr ; Select next bit
|
||||||
tax
|
tax
|
||||||
bne @loop ; Stop when mask is 0
|
bne @loop ; Stop when mask is 0
|
||||||
|
lda #SPI_SSn ; Raise Slave Select
|
||||||
|
sta BB_SPI_BASE
|
||||||
ply ; Restore regs
|
ply ; Restore regs
|
||||||
plx
|
plx
|
||||||
rts ; Return
|
rts ; Return
|
||||||
|
|||||||
Reference in New Issue
Block a user