void init_pwmled();
void pwmled_adc(unsigned char n, uint16_t adcval);
void pwmled_set_mode(unsigned char n, unsigned char mode);
+void pwmled_set_brightness(uint16_t brightness);
+#define PWMLED_BRIGHTNESS(l0_lo, l0_hi, l1, l2_lo, l2_hi) ( \
+ (uint16_t)(l0_lo) \
+ | ((uint16_t)(l0_hi) << 3) \
+ | ((uint16_t)(l1) << 6) \
+ | ((uint16_t)(l2_lo) << 9) \
+ | ((uint16_t)(l2_hi) << 12) \
+ )
/* gpio.c */
void init_gpio();
#endif
};
-static uint16_t adc_vals[N_PWMLEDS*N_PWMLED_MODES] = {
-#ifdef TESTING_FW
- /* pwmled0 */
+static uint16_t adc_targets_0[] = {
MA_GAIN_TO_ADC( 50, 20),
MA_GAIN_TO_ADC( 100, 20),
+ MA_GAIN_TO_ADC( 200, 20),
MA_GAIN_TO_ADC( 350, 20),
- /* pwmled1 */
+};
+
+static uint16_t adc_targets_1[] = {
MA_GAIN_TO_ADC( 5, 20),
MA_GAIN_TO_ADC( 10, 20),
MA_GAIN_TO_ADC( 20, 20),
- /* pwmled2 */
+};
+
+static uint16_t adc_targets_2[] = {
MA_GAIN_TO_ADC( 50, 1),
- MA_GAIN_TO_ADC( 80, 1),
- MA_GAIN_TO_ADC( 150, 1)
-#else
- /* pwmled0 */
- MA_GAIN_TO_ADC( 50, 20),
- MA_GAIN_TO_ADC( 100, 20),
- MA_GAIN_TO_ADC( 350, 20),
- /* pwmled1 */
- MA_GAIN_TO_ADC( 5, 20),
- MA_GAIN_TO_ADC( 10, 20),
- MA_GAIN_TO_ADC( 23, 20),
- /* pwmled2 */
- MA_GAIN_TO_ADC( 150, 1),
- MA_GAIN_TO_ADC( 300, 1),
- MA_GAIN_TO_ADC(1500, 1)
-#endif
+ MA_GAIN_TO_ADC( 100, 1),
+ MA_GAIN_TO_ADC( 200, 1),
+ MA_GAIN_TO_ADC( 350, 1),
};
+static uint16_t adc_vals[N_PWMLEDS*N_PWMLED_MODES];
+
#define ST_DISABLED 0
#define ST_OFF 1
#define ST_PROBING 2
led->err_sums[j] = 0;
}
}
+
+ pwmled_set_brightness(PWMLED_BRIGHTNESS(0, 2, 1, 0, 2));
}
void pwmled_set_mode(unsigned char n, unsigned char mode)
}
}
+void pwmled_set_brightness(uint16_t brightness)
+{
+ unsigned char i;
+
+ adc_vals[0] = adc_targets_0[brightness & 0x7];
+ adc_vals[1] = adc_targets_0[(brightness >> 3) & 0x7];
+ adc_vals[2] = adc_vals[1];
+
+ adc_vals[3] = adc_targets_1[(brightness >> 6) & 0x7];
+ adc_vals[4] = adc_vals[3];
+ adc_vals[5] = adc_vals[3];
+
+ adc_vals[6] = adc_targets_2[(brightness >> 9) & 0x7];
+ adc_vals[7] = adc_targets_2[(brightness >> 12) & 0x7];
+ adc_vals[8] = adc_vals[7];
+
+ for (i = 0; i < N_PWMLEDS; i++)
+ pwmleds[i].err_sum = 0;
+}
+
#define PWMLED_PROBE_STEADY_COUNT 10
static inline unsigned char pwmled_probed_ok(unsigned char n, uint16_t old_pwm)