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