Skip to content

Commit

Permalink
Fix bugs in zephyr implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
natelust committed Dec 15, 2022
1 parent f0d535f commit a2f8e88
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 3 deletions.
2 changes: 1 addition & 1 deletion esphome/components/zephyr/core.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ void arch_restart() {
sys_reboot(SYS_REBOOT_COLD);
}
void arch_feed_wdt() {}
uint8_t progmem_read_byte(const uint8_t *addr) { return 0; }
uint8_t progmem_read_byte(const uint8_t *addr) { return *addr; }
}
uint32_t arch_get_cpu_cycle_count() {
return k_uptime_ticks();
Expand Down
5 changes: 5 additions & 0 deletions esphome/components/zephyr/gpio.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include "gpio.h"
#include <sys/util.h>
#include "esphome/core/log.h"

namespace esphome {
namespace zephyr {
Expand Down Expand Up @@ -61,6 +62,10 @@ void ZephyrGPIOPin::pin_mode(gpio::Flags flags) {
mode = GPIO_INPUT | GPIO_PULL_DOWN;
} else if (flags == (gpio::FLAG_OUTPUT | gpio::FLAG_OPEN_DRAIN)) {
mode = GPIO_OUTPUT | GPIO_OPEN_DRAIN;
} else if (flags == (gpio::FLAG_OUTPUT | gpio::FLAG_PULLUP)) {
mode = GPIO_OUTPUT | GPIO_PULL_UP;
} else if (flags == (gpio::FLAG_OUTPUT | gpio::FLAG_PULLDOWN)) {
mode = GPIO_OUTPUT | GPIO_PULL_DOWN;
} else {
return;
}
Expand Down
11 changes: 9 additions & 2 deletions esphome/components/zephyr/gpio.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#pragma once

#include "esphome/core/hal.h"
#include "esphome/core/log.h"
#include <drivers/gpio.h>
#include <devicetree.h>
#include <vector>
Expand All @@ -18,12 +19,18 @@ class ZephyrGPIOPin : public InternalGPIOPin{
public:
void set_pin(uint8_t pin) { pin_ = pin; }
void set_inverted(bool inverted) { inverted_ = inverted; }
void set_flags(gpio::Flags flags) { flags_ = flags; }
void set_flags(gpio::Flags flags) {
flags_ = flags;
// Set this here, as zephyr is fine with it, and
// setup does not seem to be triggering for GPIO
// devices
this->pin_mode(this->flags_);
}
void set_device(const struct device * device) {this->device = device;}
void set_device_label(const char * label) {
this->set_device(device_get_binding(label));
}
void setup() override { pin_mode(flags_); }
void setup() override { this->pin_mode(this->flags_); }
void pin_mode(gpio::Flags flags) override;
bool digital_read() override;
void digital_write(bool value) override;
Expand Down

0 comments on commit a2f8e88

Please sign in to comment.