parent
b9580b17fd
commit
eee687316e
@ -0,0 +1,64 @@ |
||||
/*
|
||||
#include <libopencm3/cm3/nvic.h> |
||||
#include <libopencm3/stm32/exti.h> |
||||
#include <libopencm3/stm32/gpio.h> |
||||
#include <libopencm3/stm32/rtc.h> |
||||
*/ |
||||
|
||||
#include <rtc.h> |
||||
|
||||
static int reset = 0; |
||||
|
||||
void rtc_alarm_isr(void) |
||||
{ |
||||
/*
|
||||
if (rtc_check_flag(RTC_ALR)) { |
||||
rtc_clear_flag(RTC_ALR); |
||||
|
||||
rtc_disable_alarm(); |
||||
exti_reset_request(EXTI17); |
||||
|
||||
if (!reset) { |
||||
reset = 1; |
||||
gpio_set(GPIOA, GPIO1); |
||||
|
||||
rtc_set_alarm_time(rtc_get_counter_val() + 5); |
||||
rtc_enable_alarm(); |
||||
} else { |
||||
reset = 0; |
||||
gpio_set(GPIOA, GPIO1); |
||||
alarm_disable(); |
||||
} |
||||
} |
||||
*/ |
||||
} |
||||
|
||||
int alarm_enable(uint32_t timeout) |
||||
{ |
||||
/*
|
||||
rtc_enable_alarm(); |
||||
rtc_set_alarm_time(rtc_get_counter_val() + timeout); |
||||
|
||||
exti_enable_request(EXTI17); |
||||
exti_set_trigger(EXTI17, EXTI_TRIGGER_RISING); |
||||
|
||||
nvic_enable_irq(NVIC_RTC_ALARM_IRQ); |
||||
nvic_set_priority(NVIC_RTC_ALARM_IRQ, 1); |
||||
|
||||
rtc_interrupt_enable(RTC_ALR); |
||||
*/ |
||||
|
||||
return 0; |
||||
} |
||||
|
||||
int alarm_disable(void) |
||||
{ |
||||
/*
|
||||
exti_disable_request(EXTI17); |
||||
nvic_disable_irq(NVIC_RTC_ALARM_IRQ); |
||||
rtc_interrupt_disable(RTC_ALR); |
||||
rtc_disable_alarm(); |
||||
*/ |
||||
|
||||
return 0; |
||||
} |
@ -0,0 +1,61 @@ |
||||
/*
|
||||
#include <libopencm3/stm32/gpio.h> |
||||
#include <libopencm3/stm32/rcc.h> |
||||
#include <libopencm3/stm32/timer.h> |
||||
*/ |
||||
|
||||
#include <sys/types.h> |
||||
#include <stdint.h> |
||||
#include <buzzer.h> |
||||
#include <macros.h> |
||||
|
||||
struct buzzer buzzers[] = { |
||||
{ }, |
||||
}; |
||||
|
||||
size_t nbuzzers = count_of(buzzers); |
||||
|
||||
void buzzer_init(struct buzzer *buzzer) |
||||
{ |
||||
/*
|
||||
rcc_periph_reset_pulse(buzzer->timer); |
||||
|
||||
timer_set_mode(buzzer->timer, TIM_CR1_CKD_CK_INT, TIM_CR1_CMS_EDGE, |
||||
TIM_CR1_DIR_UP); |
||||
|
||||
timer_set_prescaler(buzzer->timer, 72); |
||||
timer_set_repetition_counter(buzzer->timer, 0); |
||||
timer_enable_preload(buzzer->timer); |
||||
timer_enable_break_main_output(buzzer->timer); |
||||
timer_continuous_mode(buzzer->timer); |
||||
|
||||
timer_disable_oc_output(buzzer->timer, buzzer->channel); |
||||
timer_set_oc_mode(buzzer->timer, buzzer->channel, TIM_OCM_PWM1); |
||||
timer_set_oc_value(buzzer->timer, buzzer->channel, 0); |
||||
timer_enable_oc_output(buzzer->timer, buzzer->channel); |
||||
*/ |
||||
} |
||||
|
||||
void buzzer_enable(struct buzzer *buzzer) |
||||
{ |
||||
/*
|
||||
timer_enable_counter(buzzer->timer); |
||||
*/ |
||||
} |
||||
|
||||
void buzzer_disable(struct buzzer *buzzer) |
||||
{ |
||||
/*
|
||||
timer_disable_counter(buzzer->timer); |
||||
*/ |
||||
} |
||||
|
||||
void buzzer_set_freq(struct buzzer *buzzer, uint32_t freq) |
||||
{ |
||||
/*
|
||||
uint32_t period = 1000000 / freq; |
||||
|
||||
timer_set_period(buzzer->timer, period); |
||||
timer_set_oc_value(buzzer->timer, buzzer->channel, period / 2); |
||||
*/ |
||||
} |
@ -0,0 +1,53 @@ |
||||
/*
|
||||
#include <libopencm3/stm32/gpio.h> |
||||
*/ |
||||
|
||||
#include <gpio.h> |
||||
|
||||
int gpio_init(void) |
||||
{ |
||||
#if 0 |
||||
/* Set up GPIOs for SPI 1 */ |
||||
gpio_set_mode(GPIOA, GPIO_MODE_OUTPUT_50_MHZ, |
||||
GPIO_CNF_OUTPUT_PUSHPULL, GPIO_SPI1_NSS); |
||||
gpio_set_mode(GPIOA, GPIO_MODE_OUTPUT_50_MHZ, |
||||
GPIO_CNF_OUTPUT_ALTFN_PUSHPULL, GPIO_SPI1_SCK | |
||||
GPIO_SPI1_MOSI); |
||||
gpio_set_mode(GPIOA, GPIO_MODE_INPUT, GPIO_CNF_INPUT_FLOAT, |
||||
GPIO_SPI1_MISO); |
||||
|
||||
/* Set up GPIOs for user console (USART 1) */ |
||||
gpio_set_mode(GPIOA, GPIO_MODE_OUTPUT_50_MHZ, |
||||
GPIO_CNF_OUTPUT_ALTFN_PUSHPULL, GPIO_USART1_TX); |
||||
gpio_set_mode(GPIOA, GPIO_MODE_INPUT, |
||||
GPIO_CNF_INPUT_FLOAT, GPIO_USART1_RX); |
||||
|
||||
/* Set up GPIOs for admin console (USART 2) */ |
||||
gpio_set_mode(GPIOA, GPIO_MODE_OUTPUT_50_MHZ, |
||||
GPIO_CNF_OUTPUT_ALTFN_PUSHPULL, GPIO_USART2_TX); |
||||
gpio_set_mode(GPIOA, GPIO_MODE_INPUT, |
||||
GPIO_CNF_INPUT_FLOAT, GPIO_USART2_RX); |
||||
|
||||
/* Set up GPIOs for reset. */ |
||||
gpio_set_mode(GPIOA, GPIO_MODE_OUTPUT_50_MHZ, GPIO_CNF_OUTPUT_OPENDRAIN, |
||||
GPIO1); |
||||
|
||||
/* Set up GPIOs for timers. */ |
||||
gpio_primary_remap(AFIO_MAPR_SWJ_CFG_JTAG_OFF_SW_ON, |
||||
AFIO_MAPR_TIM2_REMAP_PARTIAL_REMAP1); |
||||
gpio_set_mode(GPIOA, GPIO_MODE_OUTPUT_50_MHZ, |
||||
GPIO_CNF_OUTPUT_ALTFN_PUSHPULL, GPIO_TIM2_PR1_CH1_ETR); |
||||
|
||||
/* Set up GPIO for LED. */ |
||||
gpio_set_mode(GPIOB, GPIO_MODE_OUTPUT_50_MHZ, GPIO_CNF_OUTPUT_PUSHPULL, GPIO0); |
||||
gpio_clear(GPIOB, GPIO0); |
||||
gpio_set_mode(GPIOC, GPIO_MODE_OUTPUT_50_MHZ, GPIO_CNF_OUTPUT_PUSHPULL, GPIO10); |
||||
gpio_set(GPIOC, GPIO10); |
||||
#endif |
||||
|
||||
return 0; |
||||
} |
||||
|
||||
void gpio_cleanup(void) |
||||
{ |
||||
} |
@ -0,0 +1,40 @@ |
||||
/*
|
||||
#include <libopencm3/stm32/gpio.h> |
||||
*/ |
||||
|
||||
#include <stdint.h> |
||||
#include <sys/types.h> |
||||
#include <led.h> |
||||
#include <macros.h> |
||||
|
||||
struct led leds[] = { |
||||
{ }, |
||||
}; |
||||
|
||||
size_t nleds = count_of(leds); |
||||
|
||||
void led_enable(struct led *led) |
||||
{ |
||||
/*
|
||||
if (!led) |
||||
return; |
||||
|
||||
if (led->invert) |
||||
gpio_clear(led->port, led->pin); |
||||
else |
||||
gpio_set(led->port, led->pin); |
||||
*/ |
||||
} |
||||
|
||||
void led_disable(struct led *led) |
||||
{ |
||||
/*
|
||||
if (!led) |
||||
return; |
||||
|
||||
if (led->invert) |
||||
gpio_set(led->port, led->pin); |
||||
else |
||||
gpio_clear(led->port, led->pin); |
||||
*/ |
||||
} |
@ -0,0 +1,25 @@ |
||||
/*
|
||||
#include <libopencm3/stm32/rcc.h> |
||||
*/ |
||||
|
||||
#include <rcc.h> |
||||
|
||||
int rcc_init(void) |
||||
{ |
||||
/*
|
||||
rcc_periph_clock_enable(RCC_AFIO); |
||||
rcc_periph_clock_enable(RCC_GPIOA); |
||||
rcc_periph_clock_enable(RCC_GPIOB); |
||||
rcc_periph_clock_enable(RCC_GPIOC); |
||||
rcc_periph_clock_enable(RCC_SPI1); |
||||
rcc_periph_clock_enable(RCC_USART1); |
||||
rcc_periph_clock_enable(RCC_USART2); |
||||
rcc_periph_clock_enable(RCC_TIM2); |
||||
*/ |
||||
|
||||
return 0; |
||||
} |
||||
|
||||
void rcc_cleanup(void) |
||||
{ |
||||
} |
@ -0,0 +1,22 @@ |
||||
#include <macros.h> |
||||
#include <rtc.h> |
||||
|
||||
int rtc_get_time(struct tm *time) |
||||
{ |
||||
return 0; |
||||
} |
||||
|
||||
static int rtc_set_time(struct tm *time) |
||||
{ |
||||
|
||||
return 0; |
||||
} |
||||
|
||||
int rtc_init(struct tm *time) |
||||
{ |
||||
/*
|
||||
rtc_set_time(time); |
||||
*/ |
||||
|
||||
return 0; |
||||
} |
@ -0,0 +1,45 @@ |
||||
#define _GNU_SOURCE |
||||
#include <stdint.h> |
||||
#include <stdlib.h> |
||||
|
||||
#include <spi.h> |
||||
|
||||
static int virtual_spi_tx_rx(struct spi_dev *dev, void *rx_buf, size_t rx_len, |
||||
const void *tx_buf, size_t tx_len); |
||||
|
||||
static struct spi_ops virtual_spi_ops = { |
||||
.tx_rx = virtual_spi_tx_rx, |
||||
}; |
||||
|
||||
static void virtual_spi_init(void) |
||||
{ |
||||
/* TODO */ |
||||
} |
||||
|
||||
struct spi_dev *spi_probe(void) |
||||
{ |
||||
struct spi_dev *dev; |
||||
|
||||
if (!(dev = malloc(sizeof *dev))) |
||||
return NULL; |
||||
|
||||
dev->ops = &virtual_spi_ops; |
||||
/*
|
||||
dev->dev_id = SPI1; |
||||
|
||||
*/ |
||||
virtual_spi_init(); |
||||
|
||||
return dev; |
||||
} |
||||
|
||||
void spi_release(struct spi_dev *dev) |
||||
{ |
||||
free(dev); |
||||
} |
||||
|
||||
static int virtual_spi_tx_rx(struct spi_dev *dev, void *rx_buf, size_t rx_len, |
||||
const void *tx_buf, size_t tx_len) |
||||
{ |
||||
return 0; |
||||
} |
Loading…
Reference in new issue