]> www.fi.muni.cz Git - bike-lights.git/blob - firmware/lights.h
7e7e2a4d850b18d46e469c8e75668b42f1ca1f32
[bike-lights.git] / firmware / lights.h
1 #ifndef LIGHTS_H__
2 #define LIGHTS_H__ 1
3
4 #define TESTING_FW 1
5
6 #define N_LEDS 7
7 #define N_PWMLEDS 3
8 #define N_PWMLED_MODES 4
9
10 #define N_BUTTONS 2
11
12 /* logging.c */
13 #ifdef USE_LOGGING
14 void init_log(unsigned char mcusr);
15 void log_set_state(unsigned char val);
16 void log_flush();
17 void log_byte(unsigned char byte);
18 void log_word(uint16_t word);
19 #else
20 void inline init_log(unsigned char mcusr) { }
21 void inline log_set_state(unsigned char val) { }
22 void inline log_flush() { }
23 void inline log_byte(unsigned char byte) { }
24 void inline log_word(uint16_t word) { }
25 #endif
26
27 /* adc.c */
28 #define PWMLED_ADC_SHIFT 1 /* 1<<1 measurements per single callback */
29 void init_adc();
30 void susp_adc();
31 void timer_start_slow_adcs();
32 extern volatile unsigned char adc_is_on;
33
34 /* pwm.c */
35 /*
36  * The real Timer/Counter 1 frequency should not be too close to the
37  * A/D converter frequency (125 kHz). Note that this is not the Top
38  * value of T/C 1, it is shifted by PWM_STEP_SHIFT as described in pwm.c
39  */
40 #define PWM_MAX 0x780
41 extern volatile unsigned char channels_running;
42 #define PWM_IS_ON(n)    (channels_running & (1 << (n)))
43 #define TIMER1_IS_ON()  (channels_running)
44 void init_pwm();
45 void susp_pwm();
46 void pwm_off(unsigned char n);
47 void pwm_set(unsigned char n, uint16_t stride);
48 void pwm_timer();
49 void pwm_disable_if_not_needed();
50
51 /* tmr.c */
52 extern volatile uint16_t jiffies;
53 void init_tmr();
54 void susp_tmr();
55
56 /* pwmled.c */
57 void init_pwmled();
58 void pwmled_adc(unsigned char n, uint16_t adcval);
59 void pwmled_set_mode(unsigned char n, unsigned char mode);
60
61 /* gpio.c */
62 void init_gpio();
63 void susp_gpio();
64 void gpio_set(unsigned char n, unsigned char on);
65
66 /* ambient.c */
67 #define AMBIENT_ADC_SHIFT 0     /* 1 measurement per callback */
68 void init_ambient();
69 void susp_ambient();
70 void ambient_log_min_max();
71 extern volatile unsigned char ambient_zone;
72 void ambient_adc(uint16_t adc_val);
73
74 /* pattern.c */
75 typedef struct {
76         unsigned char mode: 5;
77         unsigned char duration_fib: 3;
78 } pattern_t;
79
80 #define PATTERN_END { 0, 0 }
81 #define D_1 1
82 #define D_2 2
83 #define D_3 3
84 #define D_5 4
85 #define D_8 5
86 #define D_13 6
87 #define D_21 7
88
89 void init_pattern();
90 void patterns_next_tick();
91 void led_set_pattern(unsigned char led, pattern_t *pattern);
92 pattern_t *number_pattern(unsigned char num, unsigned char inv);
93 void pattern_reload();
94
95 /* buttons.c */
96 #define MAX_USER_PARAMS 3
97 void init_buttons();
98 void susp_buttons();
99 void timer_check_buttons();
100 void button_adc(uint16_t adcval);
101 unsigned char get_user_param(unsigned char param);
102 unsigned char buttons_wait_for_release();
103 unsigned char buttons_setup_in_progress();
104 pattern_t *buttons_setup_status0_pattern_select();
105 pattern_t *buttons_setup_status1_pattern_select();
106
107 /* battery.c */
108 extern volatile unsigned char battery_critical;
109 void battery_adc();
110 void init_battery();
111 unsigned char battery_gauge();
112
113 /* control.c */
114 extern pattern_t on1_pattern[];
115
116 void init_control();
117 void brake_on();
118 void brake_off();
119 void toggle_dim_mode();
120 void set_panic_mode();
121 pattern_t *pwmled0_pattern_select();
122 pattern_t *pwmled1_pattern_select();
123 pattern_t *pwmled2_pattern_select();
124 pattern_t *status_led_pattern_select();
125 pattern_t *illumination_led_pattern_select();
126 pattern_t *laser_pattern_select();
127
128 /* main.c */
129 void power_down(unsigned char err);
130
131 #endif /* !LIGHTS_H__ */
132