]> www.fi.muni.cz Git - bike-lights.git/blob - firmware/lights.h
0705dd12457965bef08b097268999bfe7bc90e50
[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();
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() { }
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
33 /* pwm.c */
34 /*
35  * The real Timer/Counter 1 frequency should not be too close to the
36  * A/D converter frequency (125 kHz). Note that this is not the Top
37  * value of T/C 1, it is shifted by PWM_STEP_SHIFT as described in pwm.c
38  */
39 #define PWM_MAX 0x780
40 void init_pwm();
41 void susp_pwm();
42 void pwm_off(unsigned char n);
43 void pwm_set(unsigned char n, uint16_t stride);
44 void pwm_timer();
45 void pwm_disable_if_not_needed();
46
47 /* tmr.c */
48 extern volatile uint16_t jiffies;
49 void init_tmr();
50 void susp_tmr();
51
52 /* pwmled.c */
53 void init_pwmled();
54 void pwmled_adc(unsigned char n, uint16_t adcval);
55 void pwmled_set_mode(unsigned char n, unsigned char mode);
56
57 /* gpio.c */
58 void init_gpio();
59 void susp_gpio();
60 void gpio_set(unsigned char n, unsigned char on);
61
62 /* ambient.c */
63 #define AMBIENT_ADC_SHIFT 0     /* 1 measurement per callback */
64 void init_ambient();
65 void susp_ambient();
66 void ambient_log_min_max();
67 extern volatile unsigned char ambient_zone;
68 void ambient_adc(uint16_t adc_val);
69
70 /* pattern.c */
71 typedef struct {
72         unsigned char mode: 3;
73         unsigned char duration: 5;
74 } pattern_t;
75
76 #define PATTERN_END { 0, 0 }
77 void init_pattern();
78 void patterns_next_tick();
79 void led_set_pattern(unsigned char led, pattern_t *pattern);
80 pattern_t *number_pattern(unsigned char num, unsigned char inv);
81 void pattern_reload();
82
83 /* buttons.c */
84 #define MAX_USER_PARAMS 3
85 void init_buttons();
86 void susp_buttons();
87 void timer_check_buttons();
88 void button_adc(uint16_t adcval);
89 unsigned char get_user_param(unsigned char param);
90 unsigned char buttons_wait_for_release();
91 unsigned char buttons_setup_in_progress();
92 pattern_t *buttons_setup_status0_pattern_select();
93 pattern_t *buttons_setup_status1_pattern_select();
94
95 /* battery.c */
96 extern volatile unsigned char battery_critical;
97 void battery_adc();
98 void init_battery();
99 unsigned char battery_gauge();
100
101 /* control.c */
102 extern pattern_t on1_pattern[];
103
104 void init_control();
105 void brake_on();
106 void brake_off();
107 void toggle_dim_mode();
108 void set_panic_mode();
109 pattern_t *pwmled0_pattern_select();
110 pattern_t *pwmled1_pattern_select();
111 pattern_t *pwmled2_pattern_select();
112 pattern_t *status_led_pattern_select();
113 pattern_t *illumination_led_pattern_select();
114 pattern_t *laser_pattern_select();
115
116 /* main.c */
117 void power_down();
118
119 #endif /* !LIGHTS_H__ */
120