Hi everyone!
avr_io v0.3.0 has just been released, adding support for more AVR MCUs and for timer peripherals.
During these months I also started thinking about a simple way to initialize (and possibly handle in the future) AVR projects automatically, since there's a fair bit of files and configurations that are needed or are just nice to have when working in nim.
Thus, I decided to write a simple utility in nim, called avrman (got the pun? ;) ), that allows for easy initialization of nim and c projects for AVR targets. It integrates with nimble for nim ones, and make or CMake for C ones. This will handle your .nimble files, config.nims, panicoverride, etc.. It will also generate flash targets for both nimble and make/CMake automatically, if a progstirng is provided.
Links
The following is a simple example showcasing the timer facilities of this release on an arduino uno. Notice that the combination of const + templates make it so that, even if using objects, the code footprint of these library is very small inside the library.
import avr_io
const
tim2Out = 3 # PORTD[3] - Pin 3
mcuFreq = 16e6.uint32 # The arduino clock frequency, 16MHz
proc initPwmTimer2 =
const
pwmPre = 1'u32 # No prescaler in use
pwmFreq = 1e6.uint32 # PWM frequency is 1MHz
pwmDuty = 20'u32 # PWM duty cycle is 20%
portD.asOutputPin(tim2Out)
timer2.setTimerFlag({TimCtlAFlag.comb1, wgm1, wgm0})
timer2.setTimerFlag({TimCtlBFlag.wgm2, cs0})
timer2.actuatePwm(mcuFreq, pwmDuty, pwmFreq, pwmPre)
proc loop =
initPwmTimer2()
while true:
discard
when isMainModule:
loop()
Any feedback is incredibly welcome!
Hi thanks! The plan is to eventually add them all, at least for the mega/tinyAVR families.
Were you thinking about a specific microcontroller? Maybe I can have a look; note that I will only test what I got on hands tho!