bh1750 i2c light sensor driver + pwm cleanup (#330)
Add bh1750 (I2C light sensor) driver + usage example
This commit is contained in:
parent
31ef50c9a9
commit
b3f658bdbf
7 changed files with 170 additions and 7 deletions
|
@ -29,7 +29,7 @@ typedef struct pwmInfoDefinition
|
|||
uint8_t running;
|
||||
|
||||
uint16_t freq;
|
||||
uint16_t dutyCicle;
|
||||
uint16_t dutyCycle;
|
||||
|
||||
/* private */
|
||||
uint32_t _maxLoad;
|
||||
|
@ -66,7 +66,7 @@ static void frc1_interrupt_handler(void)
|
|||
pwmInfo._step = step;
|
||||
}
|
||||
|
||||
void pwm_init(uint8_t npins, uint8_t* pins)
|
||||
void pwm_init(uint8_t npins, const uint8_t* pins)
|
||||
{
|
||||
/* Assert number of pins is correct */
|
||||
if (npins > MAX_PWM_PINS)
|
||||
|
@ -127,10 +127,10 @@ void pwm_set_duty(uint16_t duty)
|
|||
{
|
||||
bool output;
|
||||
|
||||
pwmInfo.dutyCicle = duty;
|
||||
pwmInfo.dutyCycle = duty;
|
||||
if (duty > 0 && duty < UINT16_MAX) {
|
||||
pwm_restart();
|
||||
return;
|
||||
return;
|
||||
}
|
||||
|
||||
// 0% and 100% duty cycle are special cases: constant output.
|
||||
|
@ -139,7 +139,7 @@ void pwm_set_duty(uint16_t duty)
|
|||
output = (duty == UINT16_MAX);
|
||||
for (uint8_t i = 0; i < pwmInfo.usedPins; ++i)
|
||||
{
|
||||
gpio_write(pwmInfo.pins[i].pin, output);
|
||||
gpio_write(pwmInfo.pins[i].pin, output);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -154,7 +154,7 @@ void pwm_restart()
|
|||
|
||||
void pwm_start()
|
||||
{
|
||||
pwmInfo._onLoad = pwmInfo.dutyCicle * pwmInfo._maxLoad / UINT16_MAX;
|
||||
pwmInfo._onLoad = pwmInfo.dutyCycle * pwmInfo._maxLoad / UINT16_MAX;
|
||||
pwmInfo._offLoad = pwmInfo._maxLoad - pwmInfo._onLoad;
|
||||
pwmInfo._step = PERIOD_ON;
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue