New ipmlemendtaion of pin interface in C

interrupts
key 4 years ago
parent 3575bb4c5a
commit b98868c432

@ -29,7 +29,6 @@ set(INTERFACES_DIR ${CMAKE_SOURCE_DIR}/bsl/csl/interfaces)
#################################################################################################### ####################################################################################################
include(${PROJECT_DEFS}) include(${PROJECT_DEFS})
add_subdirectory(bsl) add_subdirectory(bsl)
add_subdirectory(drivers/led)
set(BSL_HEADER_FILE ${CMAKE_SOURCE_DIR}/bsl/raspberry/bsl_raspberry.hpp) set(BSL_HEADER_FILE ${CMAKE_SOURCE_DIR}/bsl/raspberry/bsl_raspberry.hpp)

@ -0,0 +1,132 @@
#ifndef _GPIO_H_
#define _GPIO_H_
#ifdef __cplusplus
extern "C" {
#endif
#include <unistd.h>
#include <stdint.h>
#ifdef ARM_MCU
#include "../stm32f042/Drivers/CMSIS/Device/ST/STM32F0xx/Include/stm32f042x6.h"
typedef enum
{
pinA0 = GPIOA_BASE || 0,
pinA1 = GPIOA_BASE || 1,
pinA2 = GPIOA_BASE || 2,
pinA3 = GPIOA_BASE || 3,
pinA4 = GPIOA_BASE || 4,
pinA5 = GPIOA_BASE || 5,
pinA6 = GPIOA_BASE || 6,
pinA7 = GPIOA_BASE || 7,
pinA8 = GPIOA_BASE || 8,
pinA9 = GPIOA_BASE || 9,
pinA10 = GPIOA_BASE || 10,
pinA11 = GPIOA_BASE || 11,
pinA12 = GPIOA_BASE || 12,
pinA13 = GPIOA_BASE || 13,
pinA14 = GPIOA_BASE || 14,
pinA15 = GPIOA_BASE || 15,
pinB0 = GPIOB_BASE || 0,
pinB1 = GPIOB_BASE || 1,
pinB3 = GPIOB_BASE || 3,
pinB4 = GPIOB_BASE || 4,
pinB5 = GPIOB_BASE || 5,
pinB6 = GPIOB_BASE || 6,
pinB7 = GPIOB_BASE || 7,
pinB8 = GPIOB_BASE || 8,
pinF0 = GPIOF_BASE || 0,
pinF1 = GPIOF_BASE || 1
}pinNo_t;
#endif
#ifdef RASPBERRY
#endif
typedef enum
{
undefined,
input,
output,
analog,
alternate
}mode;
typedef enum
{
floating,
pushPull,
openDrain
}state;
typedef enum
{
none,
pullUp,
pullDown
}pullUpDown;
typedef enum
{
slow,
normal,
fast,
veryFast
}speed;
typedef enum
{
disabled,
enabled
}interrupt;
typedef struct
{
mode md;
state st;
pullUpDown pud;
speed sp;
interrupt intr;
}configuration;
typedef enum
{
notValidMode,
notValidOut,
OutOfRange,
NotDeclared,
NotReachable,
NoPullUpDown,
NotAnalog,
NotDigital,
TooFast,
Bocked,
AlreadyUsed,
NotGpio
}errors;
void setMode(pinNo_t pinNo, mode mode);
void setOutputState(pinNo_t pinNo, state state);
void setPullUpDonw(pinNo_t pinNo, pullUpDown resistance);
void setSpeed(pinNo_t pinNo, speed speed);
void config(pinNo_t pinNo, mode mode, state state, pullUpDown resistance, speed speed);
uint8_t get(pinNo_t pinNo);
void toggle(pinNo_t pinNo);
void set(pinNo_t pinNo, uint8_t state);
void init(pinNo_t pinNo);
void deInit(pinNo_t pinNo);
void hardwareInfo(pinNo_t pinNo);
void throwError();
#ifdef __cplusplus
}
#endif
#endif // _GPIO_H_

@ -1,92 +0,0 @@
#ifndef _GPIO_H_
#define _GPIO_H_
#include <unistd.h>
#include <stdint.h>
#include <memory>
class Pin
{
public:
enum mode
{
undefined,
input,
output,
analog,
alternate
};
enum state
{
floating,
pushPull,
openDrain
};
enum pullUpDown
{
none,
pullUp,
pullDown
};
enum speed
{
slow,
normal,
fast,
veryFast
};
enum interrupt
{
disabled,
enabled
};
struct configuration
{
mode md;
state st;
pullUpDown pud;
speed sp;
interrupt intr;
};
enum errors
{
notValidMode,
notValidOut,
OutOfRange,
NotDeclared,
NotReachable,
NoPullUpDown,
NotAnalog,
NotDigital,
TooFast,
Bocked,
AlreadyUsed,
NotGpio
};
virtual void setMode(mode mode) = 0;
virtual void setOutputState(state state) = 0;
virtual void setPullUpDonw(pullUpDown resistance) = 0;
virtual void setSpeed(speed speed) = 0;
virtual void config(mode mode, state state, pullUpDown resistance, speed speed) = 0;
virtual bool read() = 0;
virtual void toggle() = 0;
virtual void write(bool state) = 0;
virtual void init() = 0;
virtual void deInit() = 0;
virtual void hardwareInfo() = 0;
private:
virtual void throwError(uint16_t line, errors errNo) = 0;
};
#endif // _GPIO_H_

@ -1,8 +1,8 @@
#ifndef __STM_PIN_HPP__ #ifndef __STM_PIN_HPP__
#define __STM_PIN_HPP__ #define __STM_PIN_HPP__
#include "../../interfaces/pin.hpp" //#include "../../interfaces/pin.hpp"
#include "../Drivers/CMSIS/Device/ST/STM32F0xx/Include/stm32f042x6.h" //#include "../Drivers/CMSIS/Device/ST/STM32F0xx/Include/stm32f042x6.h"
#include <array> #include <array>
#include <stdint.h> #include <stdint.h>

@ -5,7 +5,8 @@ set (STMSRC_INCLUDES
set(STMSRC_SOURCES set(STMSRC_SOURCES
stm32f0xx_csl.c stm32f0xx_csl.c
stm32f0xx_it.c stm32f0xx_it.c
system_stm32f0xx.c) system_stm32f0xx.c
)
add_library(stmSources ${STMSRC_SOURCES}) add_library(stmSources ${STMSRC_SOURCES})
target_compile_options(stmSources PRIVATE ${C_FLAGS}) target_compile_options(stmSources PRIVATE ${C_FLAGS})
@ -19,3 +20,9 @@ target_compile_options(stmDelay PRIVATE ${C_FLAGS})
target_compile_definitions(stmDelay PRIVATE ${C_DEFS}) target_compile_definitions(stmDelay PRIVATE ${C_DEFS})
target_include_directories(stmDelay PUBLIC ${INTERFACES_DIR} ${CSL_INCLUDES}) target_include_directories(stmDelay PUBLIC ${INTERFACES_DIR} ${CSL_INCLUDES})
add_library(sub::delay ALIAS stmDelay) add_library(sub::delay ALIAS stmDelay)
add_library(stmPin pin.c)
target_compile_options(stmPin PRIVATE ${C_FLAGS})
target_compile_definitions(stmPin PRIVATE ${C_DEFS})
target_include_directories(stmPin PUBLIC ${INTERFACES_DIR} ${CSL_INCLUDES})
add_library(sub::pin ALIAS stmPin)

@ -1,8 +1,6 @@
#include "delay.hpp" #include "delay.hpp"
#include "../Inc/stm32f0xx_csl.h" #include "../Inc/stm32f0xx_csl.h"
Delay::Delay() Delay::Delay()
{ {

@ -0,0 +1,75 @@
#include "pin.h"
void setMode(pinNo_t pinNo, mode mode)
{
}
void setOutputState(pinNo_t pinNo, state state)
{
RCC->AHBENR |= RCC_AHBENR_GPIOBEN;
// Set PIN 3 of port B as Output
GPIOB->MODER |= GPIO_MODER_MODER3_0;
GPIOB->MODER &=~ GPIO_MODER_MODER3_1;
}
void setPullUpDonw(pinNo_t pinNo, pullUpDown resistance)
{
}
void setSpeed(pinNo_t pinNo, speed speed)
{
}
void config(pinNo_t pinNo, mode mode, state state, pullUpDown resistance, speed speed)
{
}
uint8_t get(pinNo_t pinNo)
{
}
void toggle(pinNo_t pinNo)
{
}
void set(pinNo_t pinNo, uint8_t state)
{
if(state == 1)
{
GPIOB->BSRR |= GPIO_BSRR_BS_3;
return;
}
GPIOB->BSRR |= GPIO_BSRR_BR_3;
}
void init(pinNo_t pinNo)
{
}
void deInit(pinNo_t pinNo)
{
}
void hardwareInfo(pinNo_t pinNo)
{
}
void throwError()
{
}

@ -74,6 +74,6 @@ set (CPP_DEFS ${C_DEFS})
list(APPEND EXTRA_LIBS sub::startup) list(APPEND EXTRA_LIBS sub::startup)
list(APPEND EXTRA_LIBS sub::translator) list(APPEND EXTRA_LIBS sub::translator)
list(APPEND EXTRA_LIBS sub::sources) list(APPEND EXTRA_LIBS sub::sources)
#list(APPEND EXTRA_LIBS sub::gpio) # TODO : PLease add this again.
list(APPEND EXTRA_LIBS sub::delay) list(APPEND EXTRA_LIBS sub::delay)
list(APPEND EXTRA_LIBS sub::led) list(APPEND EXTRA_LIBS sub::pin) # TODO : PLease add this again.
#list(APPEND EXTRA_LIBS sub::led)

@ -10,27 +10,12 @@ Nucleo_f042k6::~Nucleo_f042k6(){}
void Nucleo_f042k6::init() void Nucleo_f042k6::init()
{ {
ledPin.init();
ledPin.setMode(Pin::mode::output);
ledPin.setSpeed(Pin::speed::fast);
//Led ledGreen;
/*
pin_a0.init();
pin_a0.setMode(Pin::mode::input);
pin_a0.setSpeed(Pin::speed::slow);
pin_a0.setPullUpDonw(Pin::pullUpDown::pullDown);
*/
} }
void Nucleo_f042k6::running() void Nucleo_f042k6::running()
{ {
STM_Pin<Pin_no::pin_3, GPIO_Port::Port_B_base_address> ledPin; delay.ms(1000);
Led ledGreen(&ledPin); delay.ms(1000);
ledGreen.on();
delay.ms(200);
ledGreen.off();
delay.ms(200);
} }

@ -1,10 +1,8 @@
#ifndef BSL_NUCLEO_F042K6_H #ifndef BSL_NUCLEO_F042K6_H
#define BSL_NUCLEO_F042K6_H #define BSL_NUCLEO_F042K6_H
#include "../csl/interfaces/pin.hpp" #include "../csl/interfaces/pin.h"
#include "../csl/interfaces/delay.hpp" #include "../csl/interfaces/delay.hpp"
#include "../csl/stm32f042/Inc/stm_pin.hpp"
#include "../../drivers/led/led.hpp"
#include "stm32f0xx_csl.h" #include "stm32f0xx_csl.h"
class Nucleo_f042k6 class Nucleo_f042k6
@ -20,9 +18,6 @@ class Nucleo_f042k6
private : private :
Delay delay; Delay delay;
//STM_Pin<Pin_no::pin_0, GPIO_Port::Port_A_base_address> pin_a0;
STM_Pin<Pin_no::pin_3, GPIO_Port::Port_B_base_address> ledPin;
//Led ledGreen(&STM_Pin<Pin_no::pin_3, GPIO_Port::Port_B_base_address>);
}; };
#endif /* BSL_NUCLEO_F042K6_H */ #endif /* BSL_NUCLEO_F042K6_H */

@ -1,9 +1,6 @@
#ifndef _LED_HPP #ifndef _LED_HPP
#define _LED_HPP #define _LED_HPP
// TODO : Change Cmake to include "pin.hpp"
#include "../../bsl/csl/interfaces/pin.hpp"
#include "../../bsl/csl/interfaces/delay.hpp"
class Led class Led
{ {

@ -1,14 +1,19 @@
#include"main.hpp" #include"main.hpp"
#include"drivers/led/led.hpp" #include"bsl/csl/interfaces/delay.hpp"
//#include"bsl/csl/interfaces/pin.h"
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
Nucleo_f042k6 bsl; Delay delay;
bsl.init(); setMode(pinB3,output);
throwError();
while(1) while(1)
{ {
bsl.running(); set(pinB3,1);
delay.ms(100);
set(pinB3,0);
delay.ms(100);
} }
return 1; return 1;

Loading…
Cancel
Save