diff --git a/bsl/csl/interfaces/gpio.hpp b/bsl/csl/interfaces/gpio.hpp deleted file mode 100644 index dbd401b..0000000 --- a/bsl/csl/interfaces/gpio.hpp +++ /dev/null @@ -1,117 +0,0 @@ -#ifndef _GPIO_H_ -#define _GPIO_H_ - -#include -#include -#include - -class Gpio -{ - public: - enum pinMode - { - undefined, - input, - output, - analog, - alternate - }; - - enum pinState - { - floating, - pushPull, - openDrain - }; - - enum pinPullUpDown - { - none, - pullUp, - pullDown - }; - - enum pinSpeed - { - slow, - normal, - fast, - veryFast - }; - - enum pinInterrupt - { - disabled, - enabled - }; - - enum pinFunction - { - passive, - gpio, - i2c, - spi, - pwm, - pcm, - uart, - eeprom, - clk - }; - - struct pinDefinition - { - uint8_t no; - pinMode mode; - pinState state; - pinPullUpDown pud; - pinSpeed speed; - pinInterrupt interrupt; - pinFunction function; - }; - - enum errors - { - notValidMode, - notValidOut, - pinOutOfRange, - pinNotDeclared, - pinNotReachable, - pinNoPullUpDown, - pinNotAnalog, - pinNotDigital, - pinTooFast, - pinBocked, - pinAlreadyUsed, - pinNotGpio - }; - - Gpio(); - ~Gpio(); - - void setFunction(uint8_t gpioNo, Gpio::pinFunction function); - void setMode(uint8_t gpioNo, pinMode mode); - void setOutputState(uint8_t gpioNo, pinState state); - void setPullUpDonw(uint8_t gpioNo, pinPullUpDown resistance); - void setSpeed(uint8_t gpioNo, pinSpeed speed); - void config(uint8_t gpioNo, pinFunction function, pinMode mode, pinState state, pinPullUpDown resistance, pinSpeed speed); - - uint8_t readPin(uint8_t gpioNo); - void writePin(uint8_t gpioNo, uint8_t value); - - uint16_t readRange(uint8_t start, uint8_t stop); - void writeRange(uint8_t start, uint8_t stop, uint16_t value); - - void pinInitiate(uint8_t gpioNo); - void pinUninitiate(uint8_t gpioNo); - - void checkCurrentPins(); - void pinList(); - void pinPrintInfo(uint8_t gpioNo); - - private: - void throwError(uint16_t line, errors errNo); - class gpioImpl; - std::unique_ptr gpioPimpl; -}; - -#endif // _GPIO_H_ diff --git a/bsl/csl/interfaces/pin.hpp b/bsl/csl/interfaces/pin.hpp index 0da3daa..3d0e48d 100644 --- a/bsl/csl/interfaces/pin.hpp +++ b/bsl/csl/interfaces/pin.hpp @@ -1,23 +1,94 @@ -#ifndef __PIN_HPP__ -#define __PIN_HPP__ +#ifndef _GPIO_H_ +#define _GPIO_H_ -template -struct Pin +#include +#include +#include + +class Pin { - bool read() - { - return static_cast(this)->readImpl(); - } - - void write(bool logic) - { - static_cast(this)->writeImpl(logic); - } - - void toggle() - { - static_cast(this)-toggleImpl(); - } + 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 + }; + + Pin(); + ~Pin(); + void setMode(mode mode); + void setOutputState(state state); + void setPullUpDonw(pullUpDown resistance); + void setSpeed(speed speed); + void config(mode mode, state state, pullUpDown resistance, speed speed); + + bool read(); + bool toggle(); + void write(bool state); + + void init(); + void deInit(); + + void hardwareInfo(); + + private: + void throwError(uint16_t line, errors errNo); }; -#endif // __PIN_HPP__ +#endif // _GPIO_H_ diff --git a/bsl/csl/stm32f042/Src/CMakeLists.txt b/bsl/csl/stm32f042/Src/CMakeLists.txt index 04f13cb..82b5f71 100644 --- a/bsl/csl/stm32f042/Src/CMakeLists.txt +++ b/bsl/csl/stm32f042/Src/CMakeLists.txt @@ -1,10 +1,8 @@ set (STMSRC_INCLUDES ../Inc - ${INTERFACES_DIR} ) set(STMSRC_SOURCES - gpio.cpp stm32f0xx_csl.c stm32f0xx_it.c system_stm32f0xx.c) diff --git a/bsl/csl/stm32f042/Src/gpio.cpp b/bsl/csl/stm32f042/Src/gpio.cpp index 193c7a4..2c4d218 100644 --- a/bsl/csl/stm32f042/Src/gpio.cpp +++ b/bsl/csl/stm32f042/Src/gpio.cpp @@ -1,198 +1,82 @@ -#include "gpio.hpp" +#include "pin.hpp" #include "../Drivers/CMSIS/Device/ST/STM32F0xx/Include/stm32f042x6.h" +//#include "stm32f042x6.h" -#define PIN_COUNT 20 +Pin::Pin(){ + 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; +} +Pin::~Pin(){} -class Gpio::gpioImpl -{ - public: - uint8_t pinCount = PIN_COUNT; - char buffer[50]; - uint8_t currentPin = 0; - int ck = 0; - - - pinDefinition pins[PIN_COUNT + 1]; - - gpioImpl() - { - // Enable CLock to GPIO port B - 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 setFunction(uint8_t gpioNo, Gpio::pinFunction function) - { - - } - - void setMode(uint8_t gpioNo, Gpio::pinMode mode) - { - - } - - void setOutputState(uint8_t gpioNo, Gpio::pinState state) - { - - } - - void setPullUpDonw(uint8_t gpioNo, Gpio::pinPullUpDown resistance) - { - - } - - void setSpeed(uint8_t gpioNo, Gpio::pinSpeed speed) - { - - } - - void config(uint8_t gpioNo,Gpio::pinFunction function, Gpio::pinMode mode, Gpio::pinState state, Gpio::pinPullUpDown resistance, Gpio::pinSpeed speed) - { - - } - - - int8_t readPin(uint8_t gpioNo) - { - return 2; - } - - void writePin(uint8_t gpioNo, uint8_t value) - { - if(value == 1) - { - //LL_GPIO_SetOutputPin(LED_G_GPIO_Port,LED_G_Pin); - GPIOB->BSRR |= GPIO_BSRR_BS_3; - } - else if(value == 0) - { - //LL_GPIO_ResetOutputPin(LED_G_GPIO_Port,LED_G_Pin); - GPIOB->BSRR |= GPIO_BSRR_BR_3; - } - } - - - uint16_t readRange(uint8_t start, uint8_t stop) - { - return 0; - } - - void writeRange(uint8_t start, uint8_t stop, uint16_t value) - { - - } - - - void pinInitiate(uint8_t gpioNo) - { - - } - - void pinUninitiate(uint8_t gpioNo) - { - - } - - void checkCurrentPins() - { - } - - void pinList() // Lists allthe pins whom their mode in not set to undefined. - { - } - - void pinPrintInfo(uint8_t gpioNo) // a graphical arrangement to see the cunnrently acive pins - { - - } - - void throwError(uint16_t line, Gpio::errors errNo) - { - } -}; - -Gpio::Gpio():gpioPimpl(new gpioImpl()){} -Gpio::~Gpio(){} - -void Gpio::setFunction(uint8_t gpioNo, Gpio::pinFunction function) -{ - return gpioPimpl->setFunction(gpioNo, function); -} -void Gpio::setMode(uint8_t gpioNo, Gpio::pinMode mode) +void Pin::setMode(mode mode) { - return gpioPimpl->setMode(gpioNo, mode); + } -void Gpio::setOutputState(uint8_t gpioNo, Gpio::pinState state) +void Pin::setOutputState(state state) { - return gpioPimpl->setOutputState(gpioNo,state); + } -void Gpio::setPullUpDonw(uint8_t gpioNo, Gpio::pinPullUpDown resistance) +void Pin::setPullUpDonw(pullUpDown resistance) { - return gpioPimpl->setPullUpDonw(gpioNo,resistance); + } -void Gpio::setSpeed(uint8_t gpioNo, Gpio::pinSpeed speed) +void Pin::setSpeed(speed speed) { - return gpioPimpl->setSpeed(gpioNo, speed); + } -void Gpio::config(uint8_t gpioNo,Gpio::pinFunction function, Gpio::pinMode mode, Gpio::pinState state, Gpio::pinPullUpDown resistance, Gpio::pinSpeed speed) +void Pin::config(mode mode, state state, pullUpDown resistance, speed speed) { - return gpioPimpl->config(gpioNo,function ,mode,state,resistance,speed); + } -uint8_t Gpio::readPin(uint8_t gpioNo) -{ - return gpioPimpl->readPin(gpioNo); -} -void Gpio::writePin(uint8_t gpioNo, uint8_t value) +bool Pin::read() { - return gpioPimpl->writePin(gpioNo, value); + return 1; } -uint16_t Gpio::readRange(uint8_t start, uint8_t stop) -{ - return gpioPimpl->readRange(start,stop); -} - -void Gpio::writeRange(uint8_t start, uint8_t stop, uint16_t value) -{ - return gpioPimpl->writeRange(start,stop,value); -} - -void Gpio::pinInitiate(uint8_t gpioNo) +bool Pin::toggle() { - return gpioPimpl->pinInitiate(gpioNo); + return 1; } -void Gpio::pinUninitiate(uint8_t gpioNo) +void Pin::write(bool state) { - return gpioPimpl->pinUninitiate(gpioNo); + if(state == 1) + { + GPIOB->BSRR |= GPIO_BSRR_BS_3; + return; + } + GPIOB->BSRR |= GPIO_BSRR_BR_3; } -void Gpio::checkCurrentPins() + +void Pin::init() { - return gpioPimpl->checkCurrentPins(); + } -void Gpio::pinList() +void Pin::deInit() { - return gpioPimpl->pinList(); + } -void Gpio::pinPrintInfo(uint8_t gpioNo) + +void Pin::hardwareInfo() { - return gpioPimpl->pinPrintInfo(gpioNo); + } -void Gpio::throwError(uint16_t line, Gpio::errors error) + +void Pin::throwError(uint16_t line, errors errNo) { - return gpioPimpl->throwError(line, error); + } diff --git a/bsl/csl/stm32f042/gpio/CMakeLists.txt b/bsl/csl/stm32f042/gpio/CMakeLists.txt deleted file mode 100644 index e69de29..0000000 diff --git a/bsl/csl/stm32f042/gpio/gpioMap.hpp b/bsl/csl/stm32f042/gpio/gpioMap.hpp deleted file mode 100644 index e35d3ef..0000000 --- a/bsl/csl/stm32f042/gpio/gpioMap.hpp +++ /dev/null @@ -1,45 +0,0 @@ -/* - * My gola is to write my own gio lib - * - */ - -//USER LED GREEN -//PORT B -//PIN 3 - -//#define PERIPH_BASE (0x40000000UL) - -#define AHB1_PERIPH_OFFSET (0x00020000UL) -#define AHB1_PERIPH_BASE (PERIPH_BASE + AHB1_PERIPH_OFFSET) - -#define AHB2_PERIPH_OFFSET (0x08000000UL) -#define AHB2_PERIPH_BASE (PERIPH_BASE + AHB2_PERIPH_OFFSET) - -#define GPIOA_OFFSET (0x0000U) -//#define GPIOA_BASE (AHB2_PERIPH_BASE + GPIOA_OFFSET) - -#define GPIOB_OFFSET (0x00000400UL) -//#define GPIOB_BASE (AHB2_PERIPH_BASE + GPIOB_OFFSET) - -#define RCC_OFFSET (0x00021000UL) -//#define RCC_BASE (AHB1_PERIPH_BASE + RCC_OFFSET) -//https://stackoverflow.com/questions/18785991/define-regx-volatile-unsigned-int-x - -#define AHBENR_OFFSET (0x14UL) -#define RCC_AHBENR (*(volatile unsigned int *)(RCC_BASE + AHBENR_OFFSET)) - -#define IOPAEN (1U << 17) -#define IOPBEN (1U << 18) - - -#define MODER_OFFSET (0x00UL) -#define GPIOX_MODER (*(volatile unsigned int *)(GPIOB_BASE + MODER_OFFSET)) - -#define GPIOX_ODR_OFFSET (0x14UL) -#define GPIOB_ODR (*(volatile unsigned int *)(GPIOB_BASE + GPIOX_ODR_OFFSET)) - -#define PINB3 (1U<<3) - - - -#define LED_PIN PINB3 diff --git a/main.cpp b/main.cpp index 785d79c..a5d519b 100644 --- a/main.cpp +++ b/main.cpp @@ -1,17 +1,18 @@ #include"main.hpp" -#include "bsl/csl/interfaces/gpio.hpp" +#include "bsl/csl/interfaces/pin.hpp" int main(int argc, char *argv[]) { - Gpio gpio; + Pin pin; + cppHook(); while(1) { - LL_mDelay(50); - gpio.writePin(1,1); - LL_mDelay(50); - gpio.writePin(1,0); + LL_mDelay(500); + pin.write(true); + LL_mDelay(500); + pin.write(false); } return 1; } diff --git a/periferals/CMakeLists.txt b/periferals/CMakeLists.txt deleted file mode 100644 index 62fc86a..0000000 --- a/periferals/CMakeLists.txt +++ /dev/null @@ -1,3 +0,0 @@ -project(p_periferals) - -add_subdirectory(gpio)