nrfcxx  0.1.0
C++-17 Framework for Nordic nRF5 Devices
thingy52.hpp
Go to the documentation of this file.
1 /* SPDX-License-Identifier: Apache-2.0 */
2 /* Copyright 2018-2019 Peter A. Bigot */
3 
11 #ifndef NRFCXX_BOARD_THINGY52_HPP
12 #define NRFCXX_BOARD_THINGY52_HPP
13 #pragma once
14 
15 #include <nrfcxx/gpio.hpp>
16 #include <nrfcxx/lpm.hpp>
17 #include <nrfcxx/misc/lipomon.hpp>
18 #include <nrfcxx/misc/sx1509b.hpp>
19 
20 namespace nrfcxx {
21 namespace board {
22 
36 misc::sx1509b& iox () noexcept;
37 
44 unsigned int battery_level_pptt (unsigned int batt_mV);
45 
66 int led_setup_battery_display (unsigned int batt_mV);
67 
80 int enable_led_driver (unsigned int iox_mask = 0,
81  bool linear = false) noexcept;
82 
87 int disable_led_driver () noexcept;
88 
94 class iox_pin : public gpio::generic_pin
95 {
96 public:
101  iox_pin (int psel) :
102  bit(1U << psel),
103  psel(psel)
104  {
105  if (psel != (0x0F & psel)) {
107  }
108  }
109 
111  const uint16_t bit;
112 
114  const uint8_t psel;
115 
116  bool valid () const override
117  {
118  return true;
119  }
120 
121  void set () override
122  {
123  iox().output_sct(bit, 0);
124  }
125 
126  void clear () override
127  {
128  iox().output_sct(0, bit);
129  }
130 
131  void toggle () override
132  {
133  iox().output_sct(bit, bit);
134  }
135 
136  unsigned int configuration () const override;
137 
138  void configure (unsigned int pin_cnf) override;
139 
140  bool read () const override;
141 
142  bool is_set () const override
143  {
144  return bit & iox().gpio_cache().data;
145  }
146 };
147 
150  using super = misc::lipo_monitor;
151 public:
152 
156  power_monitor (notifier_type notify);
157 };
158 
159 } // ns board
160 } // ns nrfcxx
161 #endif /* NRFCXX_BOARD_HPP */
nrfcxx::failsafe
void failsafe(FailSafeCode code)
Record a critical system failure and reset the system.
Definition: core.hpp:1692
nrfcxx::board::enable_led_driver
int enable_led_driver(unsigned int iox_mask=0, bool linear=false) noexcept
Enable the SX1509B LED driver functionality.
nrfcxx::board::iox_pin::psel
const uint8_t psel
The pin index on the IO extender, from 0 through 15 inclusive .
Definition: thingy52.hpp:114
nrfcxx::board::iox_pin::clear
void clear() override
Set the pin to drive the output low.
Definition: thingy52.hpp:126
nrfcxx::FailSafeCode::NO_SUCH_PERIPHERAL
Application attempted to retrieve a non-existent peripheral instance.
nrfcxx::board::iox_pin::iox_pin
iox_pin(int psel)
Construct the instance.
Definition: thingy52.hpp:101
lpm.hpp
Material supporting low-power-mode operations.
nrfcxx::board::power_monitor::power_monitor
power_monitor(notifier_type notify)
Construct an instance.
gpio.hpp
Core GPIO functionality.
nrfcxx::board::iox_pin::toggle
void toggle() override
Toggle the pin drive state.
Definition: thingy52.hpp:131
nrfcxx::misc::sx1509b::gpio_cache
const gpio_regs_type & gpio_cache() const noexcept
Access the internal cache of GPIO registers.
Definition: sx1509b.hpp:82
nrfcxx::board::iox_pin
Extension of gpio::generic_pin using the SX1509B IO extender.
Definition: thingy52.hpp:94
nrfcxx::board::led_setup_battery_display
int led_setup_battery_display(unsigned int batt_mV)
Configure to display the battery level.
lipomon.hpp
Support for monitoring LiPo batteries.
nrfcxx::misc::sx1509b::output_sct
int output_sct(uint16_t set, uint16_t clear) noexcept
Multi-signal set, clear, and toggle API.
nrfcxx::board::power_monitor
Support for the power source interface.
Definition: thingy52.hpp:149
nrfcxx::board::iox_pin::bit
const uint16_t bit
The bit associated with the pin on the IO extender.
Definition: thingy52.hpp:111
nrfcxx::notifier_type
std::function< void()> notifier_type
Type used to hold a notifier.
Definition: core.hpp:514
nrfcxx::board::disable_led_driver
int disable_led_driver() noexcept
Enable the SX1509B LED driver functionality.
nrfcxx::board::iox_pin::is_set
bool is_set() const override
Return true iff the pin is valid and is configured to drive the output high.
Definition: thingy52.hpp:142
nrfcxx::lpm::lpsm_capable
Base (or mixin) class for anything that supports a state_machine.
Definition: lpm.hpp:426
nrfcxx::board::battery_level_pptt
unsigned int battery_level_pptt(unsigned int batt_mV)
Estimated battery level from measured voltage.
nrfcxx::board::iox_pin::set
void set() override
Set the pin to drive the output high.
Definition: thingy52.hpp:121
nrfcxx::misc::lipo_monitor
A state machine to monitor a LiPo battery and charger.
Definition: lipomon.hpp:49
nrfcxx::board::iox_pin::valid
bool valid() const override
Indicate whether the pin is functional.
Definition: thingy52.hpp:116
nrfcxx
Primary namespace for nrfcxx functionality.
Definition: clock.hpp:17
nrfcxx::board::iox
misc::sx1509b & iox() noexcept
Access the SX1509B instance.
sx1509b.hpp
Support for Semtex SX1509B.