diff options
author | Christian Pointner <equinox@spreadspace.org> | 2017-08-26 00:12:55 +0200 |
---|---|---|
committer | Christian Pointner <equinox@spreadspace.org> | 2017-08-26 00:12:55 +0200 |
commit | fd1895848012bc5b7f39969aea3759326dbd3ce5 (patch) | |
tree | 20e7eddb2f427e9e18baddfbee90e724b8fdb36a /lib |
initial commit
Diffstat (limited to 'lib')
-rw-r--r-- | lib/led.c | 80 | ||||
-rw-r--r-- | lib/led.h | 32 |
2 files changed, 112 insertions, 0 deletions
diff --git a/lib/led.c b/lib/led.c new file mode 100644 index 0000000..3e3d54f --- /dev/null +++ b/lib/led.c @@ -0,0 +1,80 @@ +/* + * spreadspace stm8 utils + * + * + * Copyright (C) 2017 Christian Pointner <equinox@spreadspace.org> + * + * This file is part of spreadspace stm8 utils. + * + * spreadspace stm8 utils is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * any later version. + * + * spreadspace stm8 utils is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with spreadspace stm8 utils. If not, see <http://www.gnu.org/licenses/>. + */ + +#include <stm8s.h> + +#include "led.h" + + +#if defined(__BOARD_test__) +#define NUM_LEDS 1 +#else +#define NUM_LEDS 0 +#endif + +#if defined(__BOARD_test__) +#define LED_DIR 1 +#else +#define LED_DIR 0 +#endif + +#if defined(__BOARD_test__) +#define LED_GPIO GPIOD +#define LED_PINNUM 0 +#endif + +void led_init(void) +{ +#if NUM_LEDS >= 1 + led_off(); + LED_GPIO->DDR |= 1<<LED_PINNUM; +#endif +} + +void led_on(void) +{ +#if NUM_LEDS >= 1 +#if LED_DIR == 1 + LED_GPIO->ODR |= 1<<LED_PINNUM; +#else + LED_GPIO->ODR &= ~(1<<LED_PINNUM); +#endif +#endif +} + +void led_off(void) +{ +#if NUM_LEDS >= 1 +#if LED_DIR == 1 + LED_GPIO->ODR &= ~(1<<LED_PINNUM); +#else + LED_GPIO->ODR |= 1<<LED_PINNUM; +#endif +#endif +} + +void led_toggle(void) +{ +#if NUM_LEDS >= 1 + LED_GPIO->ODR ^= 1<<LED_PINNUM; +#endif +} diff --git a/lib/led.h b/lib/led.h new file mode 100644 index 0000000..03cebc6 --- /dev/null +++ b/lib/led.h @@ -0,0 +1,32 @@ +/* + * spreadspace stm8 utils + * + * + * Copyright (C) 2017 Christian Pointner <equinox@spreadspace.org> + * + * This file is part of spreadspace stm8 utils. + * + * spreadspace stm8 utils is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * any later version. + * + * spreadspace stm8 utils is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with spreadspace stm8 utils. If not, see <http://www.gnu.org/licenses/>. + */ + +#ifndef SPREADSTM8_led_h_INCLUDED +#define SPREADSTM8_led_h_INCLUDED + +void led_init(void); + +void led_on(void); +void led_off(void); +void led_toggle(void); + +#endif |