diff options
| author | Joey Castillo <jose.castillo@gmail.com> | 2021-04-25 22:43:47 -0400 | 
|---|---|---|
| committer | Joey Castillo <jose.castillo@gmail.com> | 2021-04-25 22:43:47 -0400 | 
| commit | efd1e8a1238af8eea53afa0d5acac071d73d1ea5 (patch) | |
| tree | b64949c782f61f6a759a70f22fe32342c0dc0f27 /Smol Watch Project/My Project/examples/driver_examples.c | |
| parent | 9dda14e554137e0b0ca02b61158b5580d0728332 (diff) | |
| download | Sensor-Watch-efd1e8a1238af8eea53afa0d5acac071d73d1ea5.tar.gz Sensor-Watch-efd1e8a1238af8eea53afa0d5acac071d73d1ea5.tar.bz2 Sensor-Watch-efd1e8a1238af8eea53afa0d5acac071d73d1ea5.zip | |
WIP simple C-based library for hacking on the watch
Diffstat (limited to 'Smol Watch Project/My Project/examples/driver_examples.c')
| -rw-r--r-- | Smol Watch Project/My Project/examples/driver_examples.c | 126 | 
1 files changed, 126 insertions, 0 deletions
| diff --git a/Smol Watch Project/My Project/examples/driver_examples.c b/Smol Watch Project/My Project/examples/driver_examples.c new file mode 100644 index 00000000..19327003 --- /dev/null +++ b/Smol Watch Project/My Project/examples/driver_examples.c @@ -0,0 +1,126 @@ +/* + * Code generated from Atmel Start. + * + * This file will be overwritten when reconfiguring your Atmel Start project. + * Please copy examples or other code you want to keep to a separate file + * to avoid losing it when reconfiguring. + */ + +#include "driver_examples.h" +#include "driver_init.h" +#include "utils.h" + +/** + * Example of using ADC_0 to generate waveform. + */ +void ADC_0_example(void) +{ +	uint8_t buffer[2]; + +	adc_sync_enable_channel(&ADC_0, 0); + +	while (1) { +		adc_sync_read_channel(&ADC_0, 0, buffer, 2); +	} +} + +static void button_on_PB05_pressed(void) +{ +} + +static void button_on_PA22_pressed(void) +{ +} + +static void button_on_PA23_pressed(void) +{ +} + +/** + * Example of using EXTERNAL_IRQ_0 + */ +void EXTERNAL_IRQ_0_example(void) +{ + +	ext_irq_register(PIN_PB05, button_on_PB05_pressed); +	ext_irq_register(PIN_PA22, button_on_PA22_pressed); +	ext_irq_register(PIN_PA23, button_on_PA23_pressed); +} + +/** + * Example of using CALENDAR_0. + */ +static struct calendar_alarm alarm; + +static void alarm_cb(struct calendar_descriptor *const descr) +{ +	/* alarm expired */ +} + +void CALENDAR_0_example(void) +{ +	struct calendar_date date; +	struct calendar_time time; + +	calendar_enable(&CALENDAR_0); + +	date.year  = 2000; +	date.month = 12; +	date.day   = 31; + +	time.hour = 12; +	time.min  = 59; +	time.sec  = 59; + +	calendar_set_date(&CALENDAR_0, &date); +	calendar_set_time(&CALENDAR_0, &time); + +	alarm.cal_alarm.datetime.time.sec = 4; +	alarm.cal_alarm.option            = CALENDAR_ALARM_MATCH_SEC; +	alarm.cal_alarm.mode              = REPEAT; + +	calendar_set_alarm(&CALENDAR_0, &alarm, alarm_cb); +} + +void I2C_0_example(void) +{ +	struct io_descriptor *I2C_0_io; + +	i2c_m_sync_get_io_descriptor(&I2C_0, &I2C_0_io); +	i2c_m_sync_enable(&I2C_0); +	i2c_m_sync_set_slaveaddr(&I2C_0, 0x12, I2C_M_SEVEN); +	io_write(I2C_0_io, (uint8_t *)"Hello World!", 12); +} + +void delay_example(void) +{ +	delay_ms(5000); +} + +/** + * Example of using PWM_0. + */ +void PWM_0_example(void) +{ +	pwm_set_parameters(&PWM_0, 10000, 5000); +	pwm_enable(&PWM_0); +} + +/** + * Example of using PWM_1. + */ +void PWM_1_example(void) +{ +	pwm_set_parameters(&PWM_1, 10000, 5000); +	pwm_enable(&PWM_1); +} + +#define SLCD_EXAMPLE_SEGID SLCD_SEGID(1, 0) +/** + * Example of using SEGMENT_LCD_0 + */ +void SEGMENT_LCD_0_example(void) +{ +	slcd_sync_enable(&SEGMENT_LCD_0); +	slcd_sync_seg_on(&SEGMENT_LCD_0, SLCD_EXAMPLE_SEGID); +} | 
