Skip to content

Commit

Permalink
#45 Fixes to compilation issues in pins system
Browse files Browse the repository at this point in the history
  • Loading branch information
Robert committed Dec 23, 2022
1 parent 33d53dd commit 897f6b2
Show file tree
Hide file tree
Showing 11 changed files with 209 additions and 216 deletions.
34 changes: 34 additions & 0 deletions receivers/native/arm/peripherals/pins/all/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<parent>
<groupId>org.zcode</groupId>
<artifactId>zcode-receivers-pins</artifactId>
<version>0.0.1-SNAPSHOT</version>
</parent>

<artifactId>zcode-receivers-pins-all</artifactId>
<packaging>nar</packaging>
<name>Zcode full peripheral set</name>

<dependencies>
<dependency>
<groupId>org.zcode</groupId>
<artifactId>zcode-receivers-pins-core</artifactId>
<version>${project.version}</version>
<type>nar</type>
</dependency>
<dependency>
<groupId>org.zcode</groupId>
<artifactId>zcode-receivers-pins-ll</artifactId>
<version>${project.version}</version>
<type>nar</type>
</dependency>
<dependency>
<groupId>org.zcode</groupId>
<artifactId>zcode-receivers-pins-ll-stm32</artifactId>
<version>${project.version}</version>
<type>nar</type>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -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 <zcode/modules/ZcodeModule.hpp>

#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<ZP>::execute)
#if defined(PINS_LL)
#include <pins-ll/ZcodePinModule.hpp>

template<class ZP>
class ZcodePinModule: public ZcodeModule<ZP> {
typedef typename ZP::Strings::string_t string_t;
typedef typename ZP::LL LL;

public:

static void init() {
GpioManager<LL>::init();
#ifdef HAS_ATOD_SYSTEM
AtoDManager<LL>::init();
#else
#error No Pin system specified for usage
#endif
}

static GpioPin<LL> getPin(GpioPinName name) {
return GpioManager<LL>::getPin(name);
}

static void execute(ZcodeExecutionCommandSlot<ZP> slot, uint8_t bottomBits) {
switch (bottomBits) {
case 0x0:
ZcodePinCapabilitiesCommand<ZP>::execute(slot);
break;
case 0x1:
ZcodePinSetupCommand<ZP>::execute(slot);
break;
case 0x2:
ZcodePinWriteCommand<ZP>::execute(slot);
break;
case 0x3:
ZcodePinReadCommand<ZP>::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_ */
Original file line number Diff line number Diff line change
@@ -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 <llIncludes.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_ */
Original file line number Diff line number Diff line change
@@ -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 <pins-ll/lowlevel/Gpio.hpp>

#include <pins-ll/lowlevel/GpioManager.hpp>

template<class LL>
void GpioPin<LL>::init() {
GpioManager<LL>::activateClock(pin);
}

template<class LL>
void GpioPin<LL>::write(bool value) {
if (value) {
GpioManager<LL>::getPort(pin)->setPin(pin);
} else {
GpioManager<LL>::getPort(pin)->resetPin(pin);
}
}

template<class LL>
void GpioPin<LL>::set() {
GpioManager<LL>::getPort(pin)->setPin(pin);
}

template<class LL>
void GpioPin<LL>::reset() {
GpioManager<LL>::getPort(pin)->resetPin(pin);
}

template<class LL>
bool GpioPin<LL>::read() {
return GpioManager<LL>::getPort(pin)->getPinValue(pin);
}

template<class LL>
void GpioPin<LL>::setOutputMode(OutputMode mode) {
GpioManager<LL>::getPort(pin)->setOutputType(pin, mode);
}

template<class LL>
void GpioPin<LL>::setPullMode(PullMode mode) {
GpioManager<LL>::getPort(pin)->setPullMode(pin, mode);
}

template<class LL>
void GpioPin<LL>::setMode(PinMode mode) {
GpioManager<LL>::getPort(pin)->setMode(pin, mode);
}

template<class LL>
void GpioPin<LL>::setOutputSpeed(PinSpeed speed) {
GpioManager<LL>::getPort(pin)->setOutputSpeed(pin, speed);
}

template<class LL>
void GpioPin<LL>::setAlternateFunction(uint8_t function) {
GpioManager<LL>::getPort(pin)->setAlternateFunction(pin, function);
}

#endif /* SRC_MAIN_CPP_ARM_NO_OS_PINS_MODULE_LOWLEVEL_SPECIFIC_GPIOCPP_HPP_ */
Original file line number Diff line number Diff line change
Expand Up @@ -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 <arm-no-os/llIncludes.hpp>
#include <llIncludes.hpp>
#include "specific/GpioPort.hpp"

template<class LL>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,8 @@
#define SRC_MAIN_CPP_ARM_NO_OS_PINS_MODULE_LOWLEVEL_GPIOMANAGER_HPP_

#define GPIOLOWLEVEL_NO_CPP
#include <arm-no-os/llIncludes.hpp>
#include <llIncludes.hpp>
#include "Gpio.hpp"
#include "specific/GpioNames.hpp"

template<class LL>
class GpioManager {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,8 @@
*/

#include "../GpioManager.hpp"
#if defined(STM32G4)
#include <arm-no-os/stm32g4/pins-module/lowlevel/specific/GpioManagercpp.hpp>
#elif defined(STM32F0)
#include <arm-no-os/stm32f0/pins-module/lowlevel/specific/GpioManagercpp.hpp>
#if defined(STM32)
#include <pins-ll-stm32/lowlevel/specific/GpioManagercpp.hpp>
#else
#error Please select a supported device family
#endif

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -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 <arm-no-os/llIncludes.hpp>
#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 <pins-ll-stm32/lowlevel/specific/GpioPort.hpp>
#else
#error Please select a supported device family
#endif
Loading

0 comments on commit 897f6b2

Please sign in to comment.