-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathVideoID.hs
114 lines (101 loc) · 2.72 KB
/
VideoID.hs
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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
----------------------------------------------------------------------------
-- |
-- Module : VideoID
-- Copyright : (c) Marc Fontaine 2016-2017
-- License : BSD3
--
-- Maintainer : [email protected]
-- Stability : experimental
-- Portability : GHC-only
--
-- Paint nice smileys in a waterfall diagram
module VideoID
where
import TRX
import IA4420
import IA4420_Register
import STM32.API as API
import STM32.GPIO as GPIO
import STM32.Timer as Timer
import STM32.DMA as DMA
import Control.Monad
import Control.Monad.IO.Class
import qualified Data.ByteString as BS
showImg :: [[Char]] -> TRX ()
showImg img = do
set FrequencyBand433
-- set FrequencyBand868
set $ OutputPower 7
-- set $ OutputPower 0
let
frequencies = [0xa000 .|. x | x <- [1560,1563..2000]]
on = 33320
off = 33288
forM_ img $ \l -> do
liftIO $ putStrLn l
set DisableTransmisson
liftSTL $ do
pinLow spi_nss
sendCommandsDMA $ codeLine frequencies on off l
delay 500000
pinHigh spi_nss
sendCommandsDMA :: [Word16] -> MI ()
sendCommandsDMA cmds = do
let len = length cmds
dmaBuffer = 0x20001000
dmaConfig = DMA.Config {
_BufferSize = fromIntegral $ len
,_Direction = PeripheralDST
,_MemoryBaseAddr = dmaBuffer
,_MemoryDataSize = HalfWord
,_MemoryInc = True
,DMA._Mode = Circular
,_PeripheralBaseAddr = regToAddr SPI2 DR
,_PeripheralDataSize = HalfWord
,_PeripheralInc = False
,_Priority = DMA.Low
}
writeMem8 dmaBuffer $ packCmds cmds
peripheralClockOn DMA1
peripheralClockOn TIM4
DMA.deInit DMA1_Channel7
DMA.disable DMA1_Channel7
DMA.init DMA1_Channel7 dmaConfig
DMA.enable DMA1_Channel7
let timeBase = TimeBase {
_Prescaler = 720
,_CounterMode = Down
,_Period = 20
,_ClockDevision = CKD_DIV1
,_RepetitionCounter =0
}
Timer.deInit TIM4
Timer.timeBaseInit TIM4 timeBase
bitReset TIM4 CR1_URS
bitSet TIM4 DIER_UDE
bitSet TIM4 CR1_CEN
packCmds :: [Word16] -> BS.ByteString
packCmds = BS.pack . concatMap lowHigh
where
lowHigh x = [fromIntegral (x .&. 0xff),fromIntegral $ x `shiftR` 8]
codeLine :: [Word16] -> Word16 -> Word16 -> [Char] -> [Word16]
codeLine freqs transOn transOff l = cmds
where
cmds = concat $ zipWith mkPoint freqs l
mkPoint f c =[transOff,f,if c==' ' then transOff else transOn,0,0,0,0]
smiley :: [[Char]]
smiley = reverse $ [
" ##### "
," ## ## "
," # # "
," # # # # "
,"# ### ### #"
,"# # # # # #"
,"# #"
,"# #"
,"# # # #"
," # ##### # "
," # ### # "
," ## ## "
," ##### "
]