]> www.fi.muni.cz Git - bike-lights.git/blob - firmware/lights.h
firmware: control logic moved to a separate module
[bike-lights.git] / firmware / lights.h
1 #ifndef LIGHTS_H__
2 #define LIGHTS_H__ 1
3
4 #define N_LEDS 7
5 #define N_PWMLEDS 3
6 #define N_PWMLED_MODES 4
7
8 #define N_BUTTONS 2
9
10 /* logging.c */
11 #ifdef USE_LOGGING
12 void init_log();
13 void log_set_state(unsigned char val);
14 void log_flush();
15 void log_byte(unsigned char byte);
16 void log_word(uint16_t word);
17 #else
18 void inline init_log() { }
19 void inline log_set_state(unsigned char val) { }
20 void inline log_flush() { }
21 void inline log_byte(unsigned char byte) { }
22 void inline log_word(uint16_t word) { }
23 #endif
24
25 /* adc.c */
26 void init_adc();
27 void susp_adc();
28
29 /* pwm.c */
30 #define PWM_MAX 0x1E4 /* This should be different than ADC frequency 125 kHz */
31 #define PWM_STEP_SHIFT 2 /* second parameter of pwm_set is shifted by
32                           * PWM_STEP_SHIFT bits to the right before setting
33                           * into HW */
34
35 void init_pwm();
36 void susp_pwm();
37 void pwm_off(unsigned char n);
38 void pwm_set(unsigned char n, uint16_t stride);
39 void pwm_timer();
40
41 /* tmr.c */
42 extern volatile uint16_t jiffies;
43 void init_tmr();
44 void susp_tmr();
45
46 /* pwmled.c */
47 void init_pwmled();
48 void pwmled_adc(unsigned char n, uint16_t adcval);
49 void pwmled_set_mode(unsigned char n, unsigned char mode);
50
51 /* gpio.c */
52 void init_gpio();
53 void susp_gpio();
54 void gpio_set(unsigned char n, unsigned char on);
55
56 /* ambient.c */
57 void init_ambient();
58 extern volatile unsigned char ambient_zone;
59 void ambient_adc(uint16_t adc_val);
60
61 /* pattern.c */
62 typedef struct {
63         unsigned char mode: 3;
64         unsigned char duration: 5;
65 } pattern_t;
66
67 #define PATTERN_FOREVER 0x1F
68 #define PATTERN_END { 0, 0 }
69 void init_pattern();
70 void patterns_next_tick();
71 void led_set_pattern(unsigned char led, pattern_t *pattern);
72 pattern_t *number_pattern(unsigned char num, unsigned char inv);
73 void pattern_reload();
74
75 /* buttons.c */
76 #define MAX_USER_PARAMS 3
77 void init_buttons();
78 void susp_buttons();
79 void timer_check_buttons();
80 unsigned char get_user_param(unsigned char param);
81 unsigned char buttons_wait_for_release();
82 unsigned char buttons_setup_in_progress();
83 pattern_t *buttons_setup_status0_pattern_select();
84 pattern_t *buttons_setup_status1_pattern_select();
85
86 /* battery.c */
87 extern volatile unsigned char battery_100mv;
88 void battery_adc();
89 void init_battery();
90
91 /* control.c */
92 extern pattern_t on1_pattern[];
93
94 void init_control();
95 void toggle_dim_mode();
96 void set_panic_mode();
97 pattern_t *pwmled0_pattern_select();
98 pattern_t *pwmled1_pattern_select();
99 pattern_t *pwmled2_pattern_select();
100 pattern_t *status_led_pattern_select();
101 pattern_t *illumination_led_pattern_select();
102
103 /* main.c */
104 void power_down();
105
106 #endif /* !LIGHTS_H__ */
107