forked from VK6TT/stm8ef-nRF24L01-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Pong
60 lines (47 loc) · 1.29 KB
/
Pong
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
\res MCU: STM8S103
\res export BIT0 BIT1 BIT2 BIT3 BIT4 BIT5 BIT6 BIT7
\res export PB_ODR PB_DDR PB_CR1 PB_CR2
#require ]B!
NVM
5 CONSTANT _LED \ Led connected to port B, Pin 5
: Setup_B ( -- )
BIT5 PB_DDR C! \ Port B outputs
BIT5 PB_CR1 C! \ set up as push pull outputs
;
: LED.On ( -- ) [ 0 PB_ODR _LED ]B! ;
: LED.Off ( -- ) [ 1 PB_ODR _LED ]B! ;
: FlashLed ( -- ) LED.ON 2 ms LED.Off ;
: TX.PWR0 ( -- ) \ SEt to 0dBm output and 250kbps
[ $0 BIT5 >HIGH BIT2 >HIGH BIT1 >HIGH ] LITERAL $06 nRF!1
;
: PAYLOAD.RX ( -- ) \ stores n bytes as set by P0_width in MYBUFF
BEGIN
RX_DR? \ wait until data is ready
UNTIL
\ >STANDBY1 ( this is optional )
MYBUFF P0_WIDTH nrf>b DROP
_CSN.HIGH
BIT6 R.STATUS nRF!1
CLR_INT
\ _CE.HD ( like >STANDBY this is optional ) \ go back to being a RX
;
: TESTRX ( -- )
(RX) \ now acting as a RX in standby state
TX.PWR0
_CE.HD \ Enter RX state
BEGIN
RX_DR? IF
PAYLOAD.RX
MYBUFF P0_WIDTH TYPE CR
THEN
?RX \ input on serial line
IF 32 = ELSE 0 THEN \ only if it is a space char do we exit
UNTIL
;
: Pong ( -- ) \ on power up flash led so we know device is a pong
Setup_B
FlashLed 500 ms FlashLed
TESTRX
;
' Pong 'Boot !
RAM