-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathmain.fs
82 lines (63 loc) · 1.88 KB
/
main.fs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
NVM
#require WIPE
32 CONSTANT P0_WIDTH \ bytes in a payload. 1-32 bytes
VARIABLE MYBUFF P0_WIDTH 1- ALLOT
VARIABLE RXBUFF P0_WIDTH 1- ALLOT
WIPE
\res MCU: STM8S103
\res export SPI_CR1 SPI_CR2 SPI_DR SPI_SR
\res export PB_ODR PB_DDR PB_CR1
\res export PC_ODR PC_DDR PC_CR1 PC_CR2
\res export PD_ODR PD_DDR PD_CR1 PD_CR2
\res export EXTI_CR1
#require ]B!
#require ]C!
5 CONSTANT _LED \ Led connected to port B5
4 CONSTANT _IRQ \ pin _IRQ on nRF24L01 connected to port C4
3 CONSTANT _CSN \ pin _CSN on nRF24L01 connected to port D3
2 CONSTANT _CE \ pin _CE on nRF24L01 connected to port D2
NVM
#require hw/spi.fs
\ timing **************************************************
: setup_pins ( -- )
[ 1 PB_DDR _LED ]B! \ PB5 debug LED output
[ 1 PB_CR1 _LED ]B! \ set up as low-side output (PB.5 is "open drain")
[ $0C ( 0b00001100 ) PD_DDR ]C! \ Port D setup nRF24L01 outputs
[ $0C PD_CR1 ]C! \ set up as push pull outputs
[ $0C PD_CR2 ]C! \ fast mode outputs
[ $60 ( 0b01100000 ) PC_DDR ]C! \ port C: setup SPI outputs
[ $60 PC_CR1 ]C! \ set as push pull output
[ $60 PC_CR2 ]C! \ set as fast mode outputs
;
: IrqInit ( -- ) \ enable nRF24 IRQ interrupt of PC.4
[ 1 EXTI_CR1 5 ]B! \ PC falling edge interrupt
[ 1 PC_CR2 _IRQ ]B! \ PC4 IRQ
;
: LED.On ( -- ) [ 0 PB_ODR _LED ]B! ;
: LED.Off ( -- ) [ 1 PB_ODR _LED ]B! ;
: _CE.LOW ( -- )
[ 0 PD_ODR _CE ]B!
;
: _CE.HIGH ( -- )
[ 1 PD_ODR _CE ]B!
;
: _CSN.LOW ( -- )
[ 0 PD_ODR _CSN ]B!
;
: _CSN.HIGH ( -- )
[ 1 PD_ODR _CSN ]B!
;
: *10us ( n -- ) \ delay n * 10us
1- FOR [
$A62B , \ LD A,#42
$4A C, \ 1$: DEC A
$26FD , \ JRNE 1$
] NEXT
;
: ms ( n -- ) \ delay n ms
1- FOR 100 *10us NEXT
;
WIPE
#include Core
#require PERSIST
PERSIST WIPE