Created
August 2, 2020 06:26
-
-
Save OrsoEric/1f599c1a67506f9b47bed1d8197f1051 to your computer and use it in GitHub Desktop.
Longan Nano RTC PA8 Interrupt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/********************************************************************************** | |
** ENVIROMENT VARIABILE | |
**********************************************************************************/ | |
#ifndef LONGAN_NANO_LED_H_ | |
#define LONGAN_NANO_LED_H_ | |
/********************************************************************************** | |
** GLOBAL INCLUDES | |
**********************************************************************************/ | |
#include <gd32vf103.h> | |
/********************************************************************************** | |
** DEFINES | |
**********************************************************************************/ | |
/********************************************************************************** | |
** MACROS | |
**********************************************************************************/ | |
/********************************************************************************** | |
** NAMESPACE | |
**********************************************************************************/ | |
//! @namespace User My custom namespace | |
namespace Longan_nano | |
{ | |
/********************************************************************************** | |
** TYPEDEFS | |
**********************************************************************************/ | |
typedef enum _Led_color | |
{ | |
BLACK, | |
RED, | |
GREEN, | |
BLUE, | |
WHITE | |
} Led_color; | |
typedef enum _Led_gpio | |
{ | |
RED_GPIO = GPIOC, | |
GREEN_GPIO = GPIOA, | |
BLUE_GPIO = GPIOA, | |
} Led_gpio; | |
typedef enum _Led_pin | |
{ | |
RED_PIN = GPIO_PIN_13, | |
GREEN_PIN = GPIO_PIN_1, | |
BLUE_PIN = GPIO_PIN_2, | |
} Led_pin; | |
/********************************************************************************** | |
** PROTOTYPE: STRUCTURES | |
**********************************************************************************/ | |
/********************************************************************************** | |
** PROTOTYPE: GLOBAL VARIABILES | |
**********************************************************************************/ | |
/********************************************************************************** | |
** PROTOTYPE: CLASS | |
**********************************************************************************/ | |
/************************************************************************************/ | |
//! @class Longan_nano_led | |
/************************************************************************************/ | |
//! @author Orso Eric | |
//! @version 0.1 alpha | |
//! @date 2019/05 | |
//! @brief Dummy Library | |
//! @details | |
//! Verbose description \n | |
//! xxx | |
//! @pre No prerequisites | |
//! @bug None | |
//! @warning No warnings | |
//! @copyright License ? | |
//! @todo todo list | |
/************************************************************************************/ | |
class Leds | |
{ | |
//Visible to all | |
public: | |
//-------------------------------------------------------------------------- | |
// CONSTRUCTORS | |
//-------------------------------------------------------------------------- | |
//! Default constructor | |
Leds( void ); | |
//-------------------------------------------------------------------------- | |
// DESTRUCTORS | |
//-------------------------------------------------------------------------- | |
//!Default destructor | |
~Leds( void ); | |
//-------------------------------------------------------------------------- | |
// OPERATORS | |
//-------------------------------------------------------------------------- | |
//-------------------------------------------------------------------------- | |
// SETTERS | |
//-------------------------------------------------------------------------- | |
//-------------------------------------------------------------------------- | |
// GETTERS | |
//-------------------------------------------------------------------------- | |
//-------------------------------------------------------------------------- | |
// TESTERS | |
//-------------------------------------------------------------------------- | |
//-------------------------------------------------------------------------- | |
// PUBLIC METHODS | |
//-------------------------------------------------------------------------- | |
/***************************************************************************/ | |
//! @brief public static method | |
//! init | | |
/***************************************************************************/ | |
//! @return bool | false = OK | true = ERR | |
//! @details | |
//! initialize the longan nano GPIO LEDs | |
/***************************************************************************/ | |
static inline bool init( void ) | |
{ | |
//---------------------------------------------------------------- | |
// VARS | |
//---------------------------------------------------------------- | |
//---------------------------------------------------------------- | |
// BODY | |
//---------------------------------------------------------------- | |
//Clock the GPIO banks | |
rcu_periph_clock_enable(RCU_GPIOA); | |
rcu_periph_clock_enable(RCU_GPIOC); | |
//Setup the R (PC13), G (PA1) and B (PA2) LEDs | |
gpio_init(Led_gpio::RED_GPIO, GPIO_MODE_OUT_PP, GPIO_OSPEED_50MHZ,Led_pin::RED_PIN); | |
gpio_init(Led_gpio::GREEN_GPIO, GPIO_MODE_OUT_PP, GPIO_OSPEED_50MHZ,Led_pin::GREEN_PIN); | |
gpio_init(Led_gpio::BLUE_GPIO, GPIO_MODE_OUT_PP, GPIO_OSPEED_50MHZ,Led_pin::BLUE_PIN); | |
//---------------------------------------------------------------- | |
// RETURN | |
//---------------------------------------------------------------- | |
return false; //OK | |
} //End public static method: init | |
/***************************************************************************/ | |
//! @brief public static method | |
//! set_color | Led_color | |
/***************************************************************************/ | |
//! @param Led_color | color of the LED | |
//! @return bool | false = OK | true = ERR | |
//! @details | |
//! initialize the longan nano GPIO LEDs | |
/***************************************************************************/ | |
static inline bool set_color( Led_color color ) | |
{ | |
//---------------------------------------------------------------- | |
// VARS | |
//---------------------------------------------------------------- | |
//LED are inverted. SET turn them OFF | |
bit_status led_r = FlagStatus::SET; | |
bit_status led_g = FlagStatus::SET; | |
bit_status led_b = FlagStatus::SET; | |
//---------------------------------------------------------------- | |
// BODY | |
//---------------------------------------------------------------- | |
//Switch: Color | |
switch(color) | |
{ | |
case (Led_color::BLACK): | |
{ | |
break; | |
} | |
case (Led_color::WHITE): | |
{ | |
led_r = FlagStatus::RESET; | |
led_g = FlagStatus::RESET; | |
led_b = FlagStatus::RESET; | |
break; | |
} | |
default: | |
{ | |
return true; //FAIL | |
} | |
} //End Switch: Color | |
//Apply the color setting | |
gpio_bit_write( Led_gpio::RED_GPIO, Led_pin::RED_PIN, (bit_status)led_r ); | |
gpio_bit_write( Led_gpio::GREEN_GPIO, Led_pin::GREEN_PIN, (bit_status)led_g ); | |
gpio_bit_write( Led_gpio::BLUE_GPIO, Led_pin::BLUE_PIN, (bit_status)led_b ); | |
//---------------------------------------------------------------- | |
// RETURN | |
//---------------------------------------------------------------- | |
return false; //OK | |
} //End public static method: set_color | |
/***************************************************************************/ | |
//! @brief public static method | |
//! toggle | | |
/***************************************************************************/ | |
//! @return bool | false = OK | true = ERR | |
//! @details | |
//! initialize the longan nano GPIO LEDs | |
/***************************************************************************/ | |
static inline bool toggle( Led_color color ) | |
{ | |
//---------------------------------------------------------------- | |
// VARS | |
//---------------------------------------------------------------- | |
//---------------------------------------------------------------- | |
// BODY | |
//---------------------------------------------------------------- | |
//Switch: Color | |
switch(color) | |
{ | |
case (Led_color::RED): | |
{ | |
gpio_bit_write(Led_gpio::RED_GPIO, Led_pin::RED_PIN, (bit_status)(1-gpio_input_bit_get(Led_gpio::RED_GPIO, Led_pin::RED_PIN))); | |
break; | |
} | |
case (Led_color::GREEN): | |
{ | |
gpio_bit_write(Led_gpio::GREEN_GPIO, Led_pin::GREEN_PIN, (bit_status)(1-gpio_input_bit_get(Led_gpio::GREEN_GPIO, Led_pin::GREEN_PIN))); | |
break; | |
} | |
case (Led_color::BLUE): | |
{ | |
gpio_bit_write(Led_gpio::BLUE_GPIO, Led_pin::BLUE_PIN, (bit_status)(1-gpio_input_bit_get(Led_gpio::BLUE_GPIO, Led_pin::BLUE_PIN))); | |
break; | |
} | |
default: | |
{ | |
return true; //FAIL | |
} | |
} //End Switch: Color | |
//---------------------------------------------------------------- | |
// RETURN | |
//---------------------------------------------------------------- | |
return false; //OK | |
} //End public static method: toggle | |
//-------------------------------------------------------------------------- | |
// PUBLIC STATIC METHODS | |
//-------------------------------------------------------------------------- | |
//-------------------------------------------------------------------------- | |
// PUBLIC VARS | |
//-------------------------------------------------------------------------- | |
//Visible to derived classes | |
protected: | |
//-------------------------------------------------------------------------- | |
// PROTECTED METHODS | |
//-------------------------------------------------------------------------- | |
//-------------------------------------------------------------------------- | |
// PROTECTED VARS | |
//-------------------------------------------------------------------------- | |
//Visible only inside the class | |
private: | |
//-------------------------------------------------------------------------- | |
// PRIVATE METHODS | |
//-------------------------------------------------------------------------- | |
//-------------------------------------------------------------------------- | |
// PRIVATE VARS | |
//-------------------------------------------------------------------------- | |
}; //End Class: Longan_nano_led | |
/********************************************************************************** | |
** NAMESPACE | |
**********************************************************************************/ | |
} //End Namespace: Longan_nano | |
#else | |
#warning "Multiple inclusion of hader file" | |
#endif |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment