Add extracted tools: CitrineOS, OpenOCPP, ShapeShifter
- CitrineOS core extracted (CSMS OCPP 2.0.1) - OpenOCPP extracted (firmware OCPP 1.6J/2.0.1) - ShapeShifter library installed (pip install -e) - ShapeShifter specification extracted - EVerest extracted TODO updated with progress
This commit is contained in:
@@ -0,0 +1,19 @@
|
||||
load("@rules_cc//cc:defs.bzl", "cc_library")
|
||||
|
||||
cc_library(
|
||||
name = "phyverso_gpio",
|
||||
deps = [
|
||||
"//modules/HardwareDrivers/EVSE/PhyVersoBSP/phyverso_mcu_comms",
|
||||
"//lib/everest/gpio",
|
||||
"@sigslot//:sigslot",
|
||||
],
|
||||
srcs = glob([
|
||||
"**/*.h",
|
||||
"**/*.cpp",
|
||||
]),
|
||||
visibility = ["//visibility:public"],
|
||||
includes = [
|
||||
".",
|
||||
],
|
||||
copts = ["-std=c++17"],
|
||||
)
|
||||
@@ -0,0 +1,33 @@
|
||||
cmake_minimum_required(VERSION 3.10)
|
||||
|
||||
# set the project name
|
||||
project(phyverso_gpio VERSION 0.1)
|
||||
# specify the C++ standard
|
||||
set(CMAKE_CXX_STANDARD 17)
|
||||
set(CMAKE_CXX_STANDARD_REQUIRED True)
|
||||
|
||||
add_library(phyverso_gpio STATIC)
|
||||
ev_register_library_target(phyverso_gpio)
|
||||
|
||||
target_sources(phyverso_gpio
|
||||
PRIVATE
|
||||
evGpio.cpp
|
||||
)
|
||||
|
||||
target_include_directories(phyverso_gpio
|
||||
PUBLIC
|
||||
"${PROJECT_BINARY_DIR}"
|
||||
"../phyverso_mcu_comms"
|
||||
)
|
||||
|
||||
target_link_libraries(phyverso_gpio
|
||||
PUBLIC
|
||||
date::date-tz
|
||||
everest::nanopb
|
||||
PRIVATE
|
||||
Pal::Sigslot
|
||||
everest::framework
|
||||
everest::gpio
|
||||
phyverso_config
|
||||
fmt::fmt
|
||||
)
|
||||
@@ -0,0 +1,89 @@
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
// Copyright Pionix GmbH and Contributors to EVerest
|
||||
|
||||
#include "evGpio.h"
|
||||
#include <everest/logging.hpp>
|
||||
#include <fmt/format.h>
|
||||
|
||||
evGpio::evGpio(evConfig& _verso_config) : verso_config(_verso_config) {
|
||||
}
|
||||
|
||||
evGpio::~evGpio() {
|
||||
// TODO: deinit gpios?
|
||||
}
|
||||
|
||||
bool evGpio::init_gpios() {
|
||||
push_buttons[CONN1_PB_STOP].set_enabled(verso_config.conf.conn1_gpio_stop_button_enabled);
|
||||
push_buttons[CONN2_PB_STOP].set_enabled(verso_config.conf.conn2_gpio_stop_button_enabled);
|
||||
|
||||
if (push_buttons[CONN1_PB_STOP].get_enabled()) {
|
||||
Everest::GpioSettings settings;
|
||||
settings.chip_name = verso_config.conf.conn1_gpio_stop_button_bank;
|
||||
settings.line_number = verso_config.conf.conn1_gpio_stop_button_pin;
|
||||
settings.inverted = verso_config.conf.conn1_gpio_stop_button_invert;
|
||||
push_buttons[CONN1_PB_STOP].init_gpio(settings);
|
||||
if (not push_buttons[CONN1_PB_STOP].ready()) {
|
||||
EVLOG_error << "Could not initialize Connector 1 push button";
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if (push_buttons[CONN2_PB_STOP].get_enabled()) {
|
||||
Everest::GpioSettings settings;
|
||||
settings.chip_name = verso_config.conf.conn2_gpio_stop_button_bank;
|
||||
settings.line_number = verso_config.conf.conn2_gpio_stop_button_pin;
|
||||
settings.inverted = verso_config.conf.conn2_gpio_stop_button_invert;
|
||||
push_buttons[CONN2_PB_STOP].init_gpio(settings);
|
||||
if (not push_buttons[CONN2_PB_STOP].ready()) {
|
||||
EVLOG_error << "Could not initialize Connector 2 push button";
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void evGpio::run() {
|
||||
poll_thread_handle = std::thread(&evGpio::poll_thread, this);
|
||||
}
|
||||
|
||||
void evGpio::poll_thread() {
|
||||
while (true) {
|
||||
if (poll_thread_handle.shouldExit())
|
||||
break;
|
||||
|
||||
// iterate over button list
|
||||
for (int i = 0; i < NUM_PB_NAMES; i++) {
|
||||
PushButton& button = push_buttons[i];
|
||||
if (not button.get_enabled())
|
||||
continue;
|
||||
|
||||
// check if GPIO is still usable
|
||||
if (not button.ready()) {
|
||||
EVLOG_error << fmt::format("Push button {} not ready. Stopping thread.", i + 1);
|
||||
goto cleanup; // break out of polling loop immediatly and terminate thread
|
||||
}
|
||||
|
||||
button.read();
|
||||
|
||||
if (button.get_state_changed()) {
|
||||
// select which signal to send depending on button name
|
||||
switch (i) {
|
||||
case CONN1_PB_STOP:
|
||||
signal_stop_button_state(1, button.get_state());
|
||||
break;
|
||||
case CONN2_PB_STOP:
|
||||
signal_stop_button_state(2, button.get_state());
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// sleep the nominal polling interval time
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(poll_time_ms));
|
||||
}
|
||||
|
||||
cleanup : {}
|
||||
}
|
||||
@@ -0,0 +1,103 @@
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
// Copyright Pionix GmbH and Contributors to EVerest
|
||||
|
||||
#ifndef PHYVERSO_GPIO_EV_GPIO_H
|
||||
#define PHYVERSO_GPIO_EV_GPIO_H
|
||||
|
||||
#include "evConfig.h"
|
||||
#include <atomic>
|
||||
#include <chrono>
|
||||
#include <everest/gpio/gpio.hpp>
|
||||
#include <sigslot/signal.hpp>
|
||||
#include <stdexcept>
|
||||
#include <stdint.h>
|
||||
#include <utility>
|
||||
#include <utils/thread.hpp>
|
||||
|
||||
class evGpio {
|
||||
|
||||
public:
|
||||
evGpio(evConfig& _verso_config);
|
||||
~evGpio();
|
||||
|
||||
void poll_thread();
|
||||
void run();
|
||||
bool init_gpios();
|
||||
|
||||
// Read thread for serial port
|
||||
Everest::Thread poll_thread_handle;
|
||||
|
||||
// Signals to communicate state changes to other modules
|
||||
sigslot::signal<int, bool> signal_stop_button_state;
|
||||
|
||||
// List of used buttons/gpios
|
||||
enum PushButtonName {
|
||||
CONN1_PB_STOP,
|
||||
CONN2_PB_STOP,
|
||||
NUM_PB_NAMES,
|
||||
};
|
||||
|
||||
private:
|
||||
static constexpr uint32_t poll_time_ms = 10; //< time in ms between polled gpio input readings/debouncing
|
||||
|
||||
// structure to encapsulate Everest::Gpio and corresponding debounce shift register
|
||||
// for now we will use 16 consecutive 0's or 1's to correspond to a stable input level (could be 8/32/64 aswell,
|
||||
// just needs adjusting in bitmasks and bitwidths)
|
||||
struct PushButton {
|
||||
void init_gpio(const Everest::GpioSettings& settings) {
|
||||
gpio.open(settings);
|
||||
gpio.set_input();
|
||||
};
|
||||
|
||||
bool ready() {
|
||||
return gpio.is_ready();
|
||||
};
|
||||
|
||||
void read() {
|
||||
debounce_shift_reg = (debounce_shift_reg << 1) | gpio.read();
|
||||
switch (debounce_shift_reg) {
|
||||
case 0xFFFF:
|
||||
state = true;
|
||||
break;
|
||||
case 0x0000:
|
||||
state = false;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
state_changed = (last_state != state);
|
||||
|
||||
last_state = state;
|
||||
};
|
||||
|
||||
bool get_state() {
|
||||
return state;
|
||||
};
|
||||
|
||||
bool get_state_changed() {
|
||||
return state_changed;
|
||||
};
|
||||
|
||||
void set_enabled(bool _enabled) {
|
||||
enabled = _enabled;
|
||||
};
|
||||
|
||||
bool get_enabled() {
|
||||
return enabled;
|
||||
};
|
||||
|
||||
private:
|
||||
Everest::Gpio gpio;
|
||||
bool state, last_state, state_changed = false;
|
||||
bool enabled = false;
|
||||
uint16_t debounce_shift_reg = 0;
|
||||
};
|
||||
|
||||
PushButton push_buttons[NUM_PB_NAMES];
|
||||
|
||||
// config bridge (filled by json or everest module config)
|
||||
evConfig& verso_config;
|
||||
};
|
||||
|
||||
#endif // PHYVERSO_GPIO_EV_GPIO_H
|
||||
Reference in New Issue
Block a user