]> www.fi.muni.cz Git - bike-lights.git/blob - firmware/lights.h
patterns: 3 bits for duration, 5 bits for mode
[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 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: 3;
78 } pattern_t;
79
80 #define PATTERN_END { 0, 0 }
81 void init_pattern();
82 void patterns_next_tick();
83 void led_set_pattern(unsigned char led, pattern_t *pattern);
84 pattern_t *number_pattern(unsigned char num, unsigned char inv);
85 void pattern_reload();
86
87 /* buttons.c */
88 #define MAX_USER_PARAMS 3
89 void init_buttons();
90 void susp_buttons();
91 void timer_check_buttons();
92 void button_adc(uint16_t adcval);
93 unsigned char get_user_param(unsigned char param);
94 unsigned char buttons_wait_for_release();
95 unsigned char buttons_setup_in_progress();
96 pattern_t *buttons_setup_status0_pattern_select();
97 pattern_t *buttons_setup_status1_pattern_select();
98
99 /* battery.c */
100 extern volatile unsigned char battery_critical;
101 void battery_adc();
102 void init_battery();
103 unsigned char battery_gauge();
104
105 /* control.c */
106 extern pattern_t on1_pattern[];
107
108 void init_control();
109 void brake_on();
110 void brake_off();
111 void toggle_dim_mode();
112 void set_panic_mode();
113 pattern_t *pwmled0_pattern_select();
114 pattern_t *pwmled1_pattern_select();
115 pattern_t *pwmled2_pattern_select();
116 pattern_t *status_led_pattern_select();
117 pattern_t *illumination_led_pattern_select();
118 pattern_t *laser_pattern_select();
119
120 /* main.c */
121 void power_down();
122
123 #endif /* !LIGHTS_H__ */
124