2016-01-17 14:54:54 +01:00
|
|
|
/* This program 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
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*
|
|
|
|
*/
|
2016-03-24 10:37:42 +01:00
|
|
|
/** @brief global definitions and methods
|
|
|
|
* @file global.h
|
|
|
|
* @author King Kévin <kingkevin@cuvoodoo.info>
|
|
|
|
* @date 2016
|
|
|
|
*/
|
2016-02-18 10:39:08 +01:00
|
|
|
#pragma once
|
2016-01-29 11:25:30 +01:00
|
|
|
#include <libopencm3/stm32/gpio.h> // GPIO defines
|
|
|
|
#include <libopencm3/cm3/nvic.h> // interrupt defines
|
|
|
|
#include <libopencm3/stm32/exti.h> // external interrupt defines
|
|
|
|
|
2016-03-24 10:37:42 +01:00
|
|
|
/** get the length of an array */
|
2016-01-28 21:21:50 +01:00
|
|
|
#define LENGTH(x) (sizeof(x) / sizeof((x)[0]))
|
|
|
|
|
2016-03-24 10:37:42 +01:00
|
|
|
/* board LED GPIO */
|
2016-02-18 10:39:08 +01:00
|
|
|
#if defined(SYSTEM_BOARD)
|
2016-03-24 10:37:42 +01:00
|
|
|
/** on system board LED is on pin 11/PA1 */
|
|
|
|
#define LED_RCC RCC_GPIOA
|
2016-01-17 14:54:54 +01:00
|
|
|
#define LED_PORT GPIOA
|
|
|
|
#define LED_PIN GPIO1
|
2016-02-18 10:39:08 +01:00
|
|
|
#elif defined(BLUE_PILL)
|
2016-03-24 10:37:42 +01:00
|
|
|
/** on minimum system LED is on pin 2/PC13 */
|
2016-02-18 10:39:08 +01:00
|
|
|
#define LED_RCC RCC_GPIOC
|
|
|
|
#define LED_PORT GPIOC
|
|
|
|
#define LED_PIN GPIO13
|
|
|
|
#elif defined (MAPLE_MINI)
|
2016-03-24 10:37:42 +01:00
|
|
|
/** on maple mini LED is on pin 19/PB1 */
|
2016-01-29 00:24:14 +01:00
|
|
|
#define LED_RCC RCC_GPIOB
|
|
|
|
#define LED_PORT GPIOB
|
|
|
|
#define LED_PIN GPIO1
|
|
|
|
#endif
|
2016-01-17 14:54:54 +01:00
|
|
|
|
2016-03-24 10:37:42 +01:00
|
|
|
/* board user button GPIO */
|
2016-02-18 10:39:08 +01:00
|
|
|
#if defined(MAPLE_MINI)
|
2016-03-24 10:37:42 +01:00
|
|
|
/** on maple mini user button is on 32/PB8 */
|
2016-01-29 11:25:30 +01:00
|
|
|
#define BUTTON_RCC RCC_GPIOB
|
|
|
|
#define BUTTON_PORT GPIOB
|
|
|
|
#define BUTTON_PIN GPIO8
|
|
|
|
#define BUTTON_EXTI EXTI8
|
|
|
|
#define BUTTON_IRQ NVIC_EXTI9_5_IRQ
|
|
|
|
#define BUTTON_ISR exti9_5_isr
|
|
|
|
#endif
|
|
|
|
|
2016-03-24 10:37:42 +01:00
|
|
|
/** @brief switch on board LED */
|
2016-01-29 00:24:14 +01:00
|
|
|
void led_on(void);
|
2016-03-24 10:37:42 +01:00
|
|
|
/** @brief switch off board LED */
|
2016-01-29 00:24:14 +01:00
|
|
|
void led_off(void);
|
2016-03-24 10:37:42 +01:00
|
|
|
/** @brief toggle board LED */
|
2016-01-29 00:24:14 +01:00
|
|
|
void led_toggle(void);
|
2016-03-24 10:37:42 +01:00
|
|
|
/** @brief default printf output */
|
2016-01-17 14:54:54 +01:00
|
|
|
int _write(int file, char *ptr, int len);
|
2016-03-24 10:37:42 +01:00
|
|
|
/** @brief get binary representation of a number
|
|
|
|
* @param[in] binary number to represent in binary
|
|
|
|
* @param[in] rjust justify representation with leading zeros
|
|
|
|
* @return string with binary representation of the number
|
|
|
|
*/
|
2016-02-18 10:39:08 +01:00
|
|
|
char* b2s(uint32_t binary, uint8_t rjust);
|
2016-01-28 21:21:50 +01:00
|
|
|
|