diff --git a/receivers/native/arm/peripherals/pins/all/pom.xml b/receivers/native/arm/peripherals/pins/all/pom.xml new file mode 100644 index 000000000..b5f23f809 --- /dev/null +++ b/receivers/native/arm/peripherals/pins/all/pom.xml @@ -0,0 +1,34 @@ + + 4.0.0 + + + org.zcode + zcode-receivers-pins + 0.0.1-SNAPSHOT + + + zcode-receivers-pins-all + nar + Zcode full peripheral set + + + + org.zcode + zcode-receivers-pins-core + ${project.version} + nar + + + org.zcode + zcode-receivers-pins-ll + ${project.version} + nar + + + org.zcode + zcode-receivers-pins-ll-stm32 + ${project.version} + nar + + + diff --git a/receivers/native/arm/peripherals/pins/pins-core/src/main/c++/pins/ZcodePinModule.hpp b/receivers/native/arm/peripherals/pins/pins-core/src/main/c++/pins/ZcodePinModule.hpp index ea4806ec2..31d96c922 100644 --- a/receivers/native/arm/peripherals/pins/pins-core/src/main/c++/pins/ZcodePinModule.hpp +++ b/receivers/native/arm/peripherals/pins/pins-core/src/main/c++/pins/ZcodePinModule.hpp @@ -8,58 +8,11 @@ #ifndef SRC_MAIN_CPP_ARM_NO_OS_PINS_MODULE_ZCODEPINMODULE_HPP_ #define SRC_MAIN_CPP_ARM_NO_OS_PINS_MODULE_ZCODEPINMODULE_HPP_ -#ifdef ZCODE_HPP_INCLUDED -#error Must be included before Zcode.hpp -#endif - -#include - -#include "commands/ZcodePinSetupCommand.hpp" -#include "commands/ZcodePinWriteCommand.hpp" -#include "commands/ZcodePinReadCommand.hpp" -#include "commands/ZcodePinCapabilitiesCommand.hpp" -#include "pin-controller/PinController.hpp" - -#define MODULE_EXISTS_003 EXISTENCE_MARKER_UTIL -#define MODULE_SWITCH_003 MODULE_SWITCH_UTIL(ZcodePinModule::execute) +#if defined(PINS_LL) +#include -template -class ZcodePinModule: public ZcodeModule { - typedef typename ZP::Strings::string_t string_t; - typedef typename ZP::LL LL; - -public: - - static void init() { - GpioManager::init(); -#ifdef HAS_ATOD_SYSTEM - AtoDManager::init(); +#else +#error No Pin system specified for usage #endif - } - - static GpioPin getPin(GpioPinName name) { - return GpioManager::getPin(name); - } - - static void execute(ZcodeExecutionCommandSlot slot, uint8_t bottomBits) { - switch (bottomBits) { - case 0x0: - ZcodePinCapabilitiesCommand::execute(slot); - break; - case 0x1: - ZcodePinSetupCommand::execute(slot); - break; - case 0x2: - ZcodePinWriteCommand::execute(slot); - break; - case 0x3: - ZcodePinReadCommand::execute(slot); - break; - default: - slot.fail(UNKNOWN_CMD, (string_t) ZP::Strings::failParseUnknownCommand); - break; - } - } -}; #endif /* SRC_MAIN_CPP_ARM_NO_OS_PINS_MODULE_ZCODEPINMODULE_HPP_ */ diff --git a/receivers/native/arm/peripherals/pins/pins-ll-stm32/src/main/c++/pins-ll-stm32/lowlevel/specific/GpioPort.hpp b/receivers/native/arm/peripherals/pins/pins-ll-stm32/src/main/c++/pins-ll-stm32/lowlevel/specific/GpioPort.hpp new file mode 100644 index 000000000..f3bd88241 --- /dev/null +++ b/receivers/native/arm/peripherals/pins/pins-ll-stm32/src/main/c++/pins-ll-stm32/lowlevel/specific/GpioPort.hpp @@ -0,0 +1,87 @@ +/* + * Zcode Library - Command System for Microcontrollers) + * Copyright (c) 2022 Zcode team (Susan Witts, Alicia Witts) + * + * SPDX-License-Identifier: MIT + */ + +#ifndef SRC_MAIN_CPP_ARM_NO_OS_PINS_MODULE_LOWLEVEL_SPECIFIC_GPIOPORT_HPP_ +#define SRC_MAIN_CPP_ARM_NO_OS_PINS_MODULE_LOWLEVEL_SPECIFIC_GPIOPORT_HPP_ + +#include + +enum OutputMode { + PushPull, OpenDrain +}; + +enum PullMode { + NoPull, PullUp, PullDown +}; + +enum PinSpeed { + LowSpeed, MediumSpeed, HighSpeed, VeryHighSpeed +}; + +enum PinMode { + Input, Output, AlternateFunction, Analog +}; + +class GpioPort { +private: + volatile uint32_t MODE; + volatile uint32_t OTYPE; + volatile uint32_t OSPEED; + volatile uint32_t PUPD; + volatile uint32_t ID; + volatile uint32_t OD; + volatile uint32_t BSR; + volatile uint32_t LCK; + volatile uint32_t AFRL; + volatile uint32_t AFRH; + volatile uint32_t BR; + +public: + void setMode(GpioPinName pin, PinMode mode) { + MODE &= ~(0x3 << (pin.pin * 2)); + MODE |= (mode) << (pin.pin * 2); + } + + void setOutputType(GpioPinName pin, OutputMode mode) { + OTYPE &= ~(0x1 << (pin.pin)); + OTYPE |= (mode) << (pin.pin); + } + + void setOutputSpeed(GpioPinName pin, PinSpeed mode) { + OSPEED &= ~(0x3 << (pin.pin * 2)); + OSPEED |= (mode) << (pin.pin * 2); + } + + void setPullMode(GpioPinName pin, PullMode mode) { + PUPD &= ~(0x3 << (pin.pin * 2)); + PUPD |= (mode) << (pin.pin * 2); + } + + bool getPinValue(GpioPinName pin) { + return ID & (1 << pin.pin); + } + + void setPin(GpioPinName pin) { + BSR = (1 << pin.pin); + } + + void resetPin(GpioPinName pin) { + BSR = (0x10000 << pin.pin); + } + + void setAlternateFunction(GpioPinName pin, uint8_t function) { + if (pin.pin < 8) { + AFRL &= ~(0xF << (pin.pin * 4)); + AFRL |= (function << (pin.pin * 4)); + } else { + AFRH &= ~(0xF << (pin.pin * 4 - 32)); + AFRH |= (function << (pin.pin * 4 - 32)); + } + } +}; + +#endif /* SRC_MAIN_CPP_ARM_NO_OS_PINS_MODULE_LOWLEVEL_SPECIFIC_GPIOPORT_HPP_ */ diff --git a/receivers/native/arm/peripherals/pins/pins-ll-stm32/src/main/c++/pins-ll-stm32/lowlevel/specific/Gpiocpp.hpp b/receivers/native/arm/peripherals/pins/pins-ll-stm32/src/main/c++/pins-ll-stm32/lowlevel/specific/Gpiocpp.hpp new file mode 100644 index 000000000..d8253d4dd --- /dev/null +++ b/receivers/native/arm/peripherals/pins/pins-ll-stm32/src/main/c++/pins-ll-stm32/lowlevel/specific/Gpiocpp.hpp @@ -0,0 +1,69 @@ +/* + * Zcode Library - Command System for Microcontrollers) + * Copyright (c) 2022 Zcode team (Susan Witts, Alicia Witts) + * + * SPDX-License-Identifier: MIT + */ + +#ifndef SRC_MAIN_CPP_ARM_NO_OS_PINS_MODULE_LOWLEVEL_SPECIFIC_GPIOCPP_HPP_ +#define SRC_MAIN_CPP_ARM_NO_OS_PINS_MODULE_LOWLEVEL_SPECIFIC_GPIOCPP_HPP_ + +#include + +#include + +template +void GpioPin::init() { + GpioManager::activateClock(pin); +} + +template +void GpioPin::write(bool value) { + if (value) { + GpioManager::getPort(pin)->setPin(pin); + } else { + GpioManager::getPort(pin)->resetPin(pin); + } +} + +template +void GpioPin::set() { + GpioManager::getPort(pin)->setPin(pin); +} + +template +void GpioPin::reset() { + GpioManager::getPort(pin)->resetPin(pin); +} + +template +bool GpioPin::read() { + return GpioManager::getPort(pin)->getPinValue(pin); +} + +template +void GpioPin::setOutputMode(OutputMode mode) { + GpioManager::getPort(pin)->setOutputType(pin, mode); +} + +template +void GpioPin::setPullMode(PullMode mode) { + GpioManager::getPort(pin)->setPullMode(pin, mode); +} + +template +void GpioPin::setMode(PinMode mode) { + GpioManager::getPort(pin)->setMode(pin, mode); +} + +template +void GpioPin::setOutputSpeed(PinSpeed speed) { + GpioManager::getPort(pin)->setOutputSpeed(pin, speed); +} + +template +void GpioPin::setAlternateFunction(uint8_t function) { + GpioManager::getPort(pin)->setAlternateFunction(pin, function); +} + +#endif /* SRC_MAIN_CPP_ARM_NO_OS_PINS_MODULE_LOWLEVEL_SPECIFIC_GPIOCPP_HPP_ */ diff --git a/receivers/native/arm/peripherals/pins/pins-ll/src/main/c++/pins-ll/lowlevel/Gpio.hpp b/receivers/native/arm/peripherals/pins/pins-ll/src/main/c++/pins-ll/lowlevel/Gpio.hpp index 8f531392c..9ca06c4bd 100644 --- a/receivers/native/arm/peripherals/pins/pins-ll/src/main/c++/pins-ll/lowlevel/Gpio.hpp +++ b/receivers/native/arm/peripherals/pins/pins-ll/src/main/c++/pins-ll/lowlevel/Gpio.hpp @@ -8,7 +8,7 @@ #ifndef SRC_MAIN_CPP_ARM_NO_OS_PINS_MODULE_LOWLEVEL_GPIO_HPP_ #define SRC_MAIN_CPP_ARM_NO_OS_PINS_MODULE_LOWLEVEL_GPIO_HPP_ -#include +#include #include "specific/GpioPort.hpp" template diff --git a/receivers/native/arm/peripherals/pins/pins-ll/src/main/c++/pins-ll/lowlevel/GpioManager.hpp b/receivers/native/arm/peripherals/pins/pins-ll/src/main/c++/pins-ll/lowlevel/GpioManager.hpp index 27c52454f..726bf8413 100644 --- a/receivers/native/arm/peripherals/pins/pins-ll/src/main/c++/pins-ll/lowlevel/GpioManager.hpp +++ b/receivers/native/arm/peripherals/pins/pins-ll/src/main/c++/pins-ll/lowlevel/GpioManager.hpp @@ -9,9 +9,8 @@ #define SRC_MAIN_CPP_ARM_NO_OS_PINS_MODULE_LOWLEVEL_GPIOMANAGER_HPP_ #define GPIOLOWLEVEL_NO_CPP -#include +#include #include "Gpio.hpp" -#include "specific/GpioNames.hpp" template class GpioManager { diff --git a/receivers/native/arm/peripherals/pins/pins-ll/src/main/c++/pins-ll/lowlevel/specific/GpioManagercpp.hpp b/receivers/native/arm/peripherals/pins/pins-ll/src/main/c++/pins-ll/lowlevel/specific/GpioManagercpp.hpp index 7572f6c63..d7e942190 100644 --- a/receivers/native/arm/peripherals/pins/pins-ll/src/main/c++/pins-ll/lowlevel/specific/GpioManagercpp.hpp +++ b/receivers/native/arm/peripherals/pins/pins-ll/src/main/c++/pins-ll/lowlevel/specific/GpioManagercpp.hpp @@ -6,10 +6,8 @@ */ #include "../GpioManager.hpp" -#if defined(STM32G4) -#include -#elif defined(STM32F0) -#include +#if defined(STM32) +#include #else #error Please select a supported device family #endif diff --git a/receivers/native/arm/peripherals/pins/pins-ll/src/main/c++/pins-ll/lowlevel/specific/GpioNames.hpp b/receivers/native/arm/peripherals/pins/pins-ll/src/main/c++/pins-ll/lowlevel/specific/GpioNames.hpp deleted file mode 100644 index 16d2c2023..000000000 --- a/receivers/native/arm/peripherals/pins/pins-ll/src/main/c++/pins-ll/lowlevel/specific/GpioNames.hpp +++ /dev/null @@ -1,15 +0,0 @@ -/* - * Zcode Library - Command System for Microcontrollers) - * Copyright (c) 2022 Zcode team (Susan Witts, Alicia Witts) - * - * SPDX-License-Identifier: MIT - */ - -#include -#if defined(STM32G4) -#include -#elif defined(STM32F0) -#include -#else -#error Please select a supported device family -#endif diff --git a/receivers/native/arm/peripherals/pins/pins-ll/src/main/c++/pins-ll/lowlevel/specific/GpioPort.hpp b/receivers/native/arm/peripherals/pins/pins-ll/src/main/c++/pins-ll/lowlevel/specific/GpioPort.hpp index 4e70e53bc..98e070a09 100644 --- a/receivers/native/arm/peripherals/pins/pins-ll/src/main/c++/pins-ll/lowlevel/specific/GpioPort.hpp +++ b/receivers/native/arm/peripherals/pins/pins-ll/src/main/c++/pins-ll/lowlevel/specific/GpioPort.hpp @@ -5,84 +5,8 @@ * SPDX-License-Identifier: MIT */ -#ifndef SRC_MAIN_CPP_ARM_NO_OS_PINS_MODULE_LOWLEVEL_SPECIFIC_GPIOPORT_HPP_ -#define SRC_MAIN_CPP_ARM_NO_OS_PINS_MODULE_LOWLEVEL_SPECIFIC_GPIOPORT_HPP_ - -#include -#include "GpioNames.hpp" - -enum OutputMode { - PushPull, OpenDrain -}; - -enum PullMode { - NoPull, PullUp, PullDown -}; - -enum PinSpeed { - LowSpeed, MediumSpeed, HighSpeed, VeryHighSpeed -}; - -enum PinMode { - Input, Output, AlternateFunction, Analog -}; - -class GpioPort { -private: - volatile uint32_t MODE; - volatile uint32_t OTYPE; - volatile uint32_t OSPEED; - volatile uint32_t PUPD; - volatile uint32_t ID; - volatile uint32_t OD; - volatile uint32_t BSR; - volatile uint32_t LCK; - volatile uint32_t AFRL; - volatile uint32_t AFRH; - volatile uint32_t BR; - -public: - void setMode(GpioPinName pin, PinMode mode) { - MODE &= ~(0x3 << (pin.pin * 2)); - MODE |= (mode) << (pin.pin * 2); - } - - void setOutputType(GpioPinName pin, OutputMode mode) { - OTYPE &= ~(0x1 << (pin.pin)); - OTYPE |= (mode) << (pin.pin); - } - - void setOutputSpeed(GpioPinName pin, PinSpeed mode) { - OSPEED &= ~(0x3 << (pin.pin * 2)); - OSPEED |= (mode) << (pin.pin * 2); - } - - void setPullMode(GpioPinName pin, PullMode mode) { - PUPD &= ~(0x3 << (pin.pin * 2)); - PUPD |= (mode) << (pin.pin * 2); - } - - bool getPinValue(GpioPinName pin) { - return ID & (1 << pin.pin); - } - - void setPin(GpioPinName pin) { - BSR = (1 << pin.pin); - } - - void resetPin(GpioPinName pin) { - BSR = (0x10000 << pin.pin); - } - - void setAlternateFunction(GpioPinName pin, uint8_t function) { - if (pin.pin < 8) { - AFRL &= ~(0xF << (pin.pin * 4)); - AFRL |= (function << (pin.pin * 4)); - } else { - AFRH &= ~(0xF << (pin.pin * 4 - 32)); - AFRH |= (function << (pin.pin * 4 - 32)); - } - } -}; - -#endif /* SRC_MAIN_CPP_ARM_NO_OS_PINS_MODULE_LOWLEVEL_SPECIFIC_GPIOPORT_HPP_ */ +#if defined(STM32) +#include +#else +#error Please select a supported device family +#endif diff --git a/receivers/native/arm/peripherals/pins/pins-ll/src/main/c++/pins-ll/lowlevel/specific/Gpiocpp.hpp b/receivers/native/arm/peripherals/pins/pins-ll/src/main/c++/pins-ll/lowlevel/specific/Gpiocpp.hpp index 50c760211..96fe0b2a7 100644 --- a/receivers/native/arm/peripherals/pins/pins-ll/src/main/c++/pins-ll/lowlevel/specific/Gpiocpp.hpp +++ b/receivers/native/arm/peripherals/pins/pins-ll/src/main/c++/pins-ll/lowlevel/specific/Gpiocpp.hpp @@ -5,65 +5,8 @@ * SPDX-License-Identifier: MIT */ -#ifndef SRC_MAIN_CPP_ARM_NO_OS_PINS_MODULE_LOWLEVEL_SPECIFIC_GPIOCPP_HPP_ -#define SRC_MAIN_CPP_ARM_NO_OS_PINS_MODULE_LOWLEVEL_SPECIFIC_GPIOCPP_HPP_ - -#include "../Gpio.hpp" - -#include "../GpioManager.hpp" - -template -void GpioPin::init() { - GpioManager::activateClock(pin); -} - -template -void GpioPin::write(bool value) { - if (value) { - GpioManager::getPort(pin)->setPin(pin); - } else { - GpioManager::getPort(pin)->resetPin(pin); - } -} - -template -void GpioPin::set() { - GpioManager::getPort(pin)->setPin(pin); -} - -template -void GpioPin::reset() { - GpioManager::getPort(pin)->resetPin(pin); -} - -template -bool GpioPin::read() { - return GpioManager::getPort(pin)->getPinValue(pin); -} - -template -void GpioPin::setOutputMode(OutputMode mode) { - GpioManager::getPort(pin)->setOutputType(pin, mode); -} - -template -void GpioPin::setPullMode(PullMode mode) { - GpioManager::getPort(pin)->setPullMode(pin, mode); -} - -template -void GpioPin::setMode(PinMode mode) { - GpioManager::getPort(pin)->setMode(pin, mode); -} - -template -void GpioPin::setOutputSpeed(PinSpeed speed) { - GpioManager::getPort(pin)->setOutputSpeed(pin, speed); -} - -template -void GpioPin::setAlternateFunction(uint8_t function) { - GpioManager::getPort(pin)->setAlternateFunction(pin, function); -} - -#endif /* SRC_MAIN_CPP_ARM_NO_OS_PINS_MODULE_LOWLEVEL_SPECIFIC_GPIOCPP_HPP_ */ +#if defined(STM32) +#include +#else +#error Please select a supported device family +#endif diff --git a/receivers/native/arm/peripherals/pins/pom.xml b/receivers/native/arm/peripherals/pins/pom.xml index 851a25a5e..d46b39844 100644 --- a/receivers/native/arm/peripherals/pins/pom.xml +++ b/receivers/native/arm/peripherals/pins/pom.xml @@ -11,6 +11,7 @@ pom Zcode pins + all pins-core pins-ll pins-ll-stm32