summaryrefslogtreecommitdiffstats
path: root/utils/hwstub/tools/lua/stmp/pwm.lua
blob: 8b078af5a7b24d279224d8fabf8b0fd88a868af6 (plain)
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
--
-- LCDIF
--

STMP.pwm = {}

function STMP.pwm.init()
    HW.LCDIF.CTRL.SFTRST.clr()
    HW.LCDIF.CTRL.CLKGATE.clr()
end 

function STMP.pwm.enable(chan, en)
    if en then
        HW.PWM.CTRL.set(bit32.lshift(1, chan))
    else
        HW.PWM.CTRL.clr(bit32.lshift(1, chan))
    end
end

function STMP.pwm.setup(channel, period, cdiv, active, active_state, inactive, inactive_state)
    -- stop
    STMP.pwm.enable(channel, false)
    -- setup pin
    --FIXME
    -- watch the order ! active THEN period
    -- NOTE: the register value is period-1
    HW.PWM.ACTIVEn[channel].ACTIVE.write(active)
    HW.PWM.ACTIVEn[channel].INACTIVE.write(inactive)
    HW.PWM.PERIODn[channel].PERIOD.write(period - 1)
    HW.PWM.PERIODn[channel].ACTIVE_STATE.write(active_state)
    HW.PWM.PERIODn[channel].INACTIVE_STATE.write(inactive_state)
    HW.PWM.PERIODn[channel].CDIV.write(cdiv)
    -- restore
    STMP.pwm.enable(channel, true)
end