Update nuttx_PWM.c file to support multiple PWM blocks #20
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR removes global declaration of pwm_info_s structure and moves it locally to functions init() and inout() to support multiple PWM blocks. It is necessary to run for loop from 0 to CONFIG_PWM_NCHANNELS and set all channels to 0 also in inout() function, otherwise there will be hard faults. Also adds some comments as the code was getting a little bit harder to read.
I also experimented a little bit with completely removing pwm_info_s structure from init() function and then removing PWMIOC_SETCHARACTERISTICS ioctl command from that function too so init() would only open the device and then execute PWMIOC_START start command. It seemed to be working fine but then I found out that PWMIOC_SETCHARACTERISTICS should be sent before PWMIOC_START according to this https://github.com/apache/incubator-nuttx/blob/master/drivers/timers/pwm.c#L497. But maybe it is worth to take a closer look at this in the future.