Skip to content

Commit 7eaeb99

Browse files
committed
clear/set pin state on 0 and 2^res-1
1 parent a4c8d03 commit 7eaeb99

File tree

1 file changed

+22
-12
lines changed

1 file changed

+22
-12
lines changed

cores/nRF5/wiring_analog_nRF51.c

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ static uint32_t adcPrescaling = ADC_CONFIG_INPSEL_AnalogInputOneThirdPrescaling;
6868
static uint32_t readResolution = 10;
6969
static uint32_t writeResolution = 8;
7070

71-
static int8_t timerPrescaller=7;
71+
static uint32_t timerPrescaller=7;
7272
//not standard, set timer prescaller
7373
inline void pwmPrescaller( int div ) {timerPrescaller=div;}
7474

@@ -330,8 +330,11 @@ void TIMER1_IRQHandler(void)
330330
{
331331
if (NRF_TIMER1->EVENTS_COMPARE[0]) {
332332
for (int i = 0; i < PWM_CH_COUNT; i++) {
333-
if (/*pwmContext[i].src==0&*&*/pwmContext[i].pin != PIN_FREE && pwmContext[i].value != 0) {
334-
NRF_GPIO->OUTSET = (1UL << pwmContext[i].pin);
333+
if (pwmContext[i].pin != PIN_FREE) {
334+
if(pwmContext[i].value != 0)
335+
NRF_GPIO->OUTSET = (1UL << pwmContext[i].pin);
336+
else
337+
NRF_GPIO->OUTCLR = (1UL << pwmContext[i].pin);
335338
}
336339
NRF_TIMER1->TASKS_CLEAR = 1;//restart count
337340
}
@@ -340,11 +343,13 @@ void TIMER1_IRQHandler(void)
340343
}
341344

342345
for (int i = 0; i < PWM_CH_COUNT; i++) {
343-
if (/*pwmContext[i].src==0&&*/NRF_TIMER1->EVENTS_COMPARE[pwmContext[i].event]) {
344-
if (pwmContext[i].pin != PIN_FREE && pwmContext[i].value != (1<<writeResolution)-1) {
345-
NRF_GPIO->OUTCLR = (1UL << pwmContext[i].pin);
346+
if (NRF_TIMER1->EVENTS_COMPARE[pwmContext[i].event]) {
347+
if (pwmContext[i].pin != PIN_FREE) {
348+
if (pwmContext[i].value != (1<<writeResolution)-1)
349+
NRF_GPIO->OUTCLR = (1UL << pwmContext[i].pin);
350+
else
351+
NRF_GPIO->OUTSET = (1UL << pwmContext[i].pin);
346352
}
347-
348353
NRF_TIMER1->EVENTS_COMPARE[pwmContext[i].event] = 0x0UL;
349354
}
350355
}
@@ -354,19 +359,24 @@ void TIMER2_IRQHandler(void)
354359
{
355360
if (NRF_TIMER2->EVENTS_COMPARE[0]) {
356361
for (int i = PWM_CH_COUNT; i < PWM_COUNT; i++) {
357-
if (pwmContext[i].pin != PIN_FREE && pwmContext[i].value != 0) {
358-
NRF_GPIO->OUTSET = (1UL << pwmContext[i].pin);
362+
if (pwmContext[i].pin != PIN_FREE) {
363+
if(pwmContext[i].value != 0)
364+
NRF_GPIO->OUTSET = (1UL << pwmContext[i].pin);
365+
else
366+
NRF_GPIO->OUTCLR = (1UL << pwmContext[i].pin);
359367
}
360368
NRF_TIMER2->TASKS_CLEAR = 1;//restart count
361369
}
362-
363370
NRF_TIMER2->EVENTS_COMPARE[0] = 0x0UL;
364371
}
365372

366373
for (int i = PWM_CH_COUNT; i < PWM_COUNT; i++) {
367374
if (NRF_TIMER2->EVENTS_COMPARE[pwmContext[i].event]) {
368-
if (pwmContext[i].pin != PIN_FREE && pwmContext[i].value != (1<<writeResolution)-1) {
369-
NRF_GPIO->OUTCLR = (1UL << pwmContext[i].pin);
375+
if (pwmContext[i].pin != PIN_FREE) {
376+
if (pwmContext[i].value != (1<<writeResolution)-1)
377+
NRF_GPIO->OUTCLR = (1UL << pwmContext[i].pin);
378+
else
379+
NRF_GPIO->OUTSET = (1UL << pwmContext[i].pin);
370380
}
371381
NRF_TIMER2->EVENTS_COMPARE[pwmContext[i].event] = 0x0UL;
372382
}

0 commit comments

Comments
 (0)