SatCat5
cfgbus_piezo.h
1 // Copyright 2025 The Aerospace Corporation.
3 // This file is a part of SatCat5, licensed under CERN-OHL-W v2 or later.
5 // ConfigBus-controlled piezoelectric buzzer
6 
7 #pragma once
8 
9 #include <satcat5/cfgbus_core.h>
10 #include <satcat5/pkt_buffer.h>
11 #include <satcat5/polling.h>
12 
13 // Default buffer size for queued notes.
14 #ifndef SATCAT5_PIEZO_BUFFER
15 #define SATCAT5_PIEZO_BUFFER 32
16 #endif
17 
18 namespace satcat5 {
19  namespace cfg {
24  class Piezo
26  , public satcat5::poll::Timer
27  {
28  public:
31  unsigned devaddr, unsigned regaddr = 0);
32 
34  void flush();
35 
39  inline satcat5::io::Writeable* queue() { return &m_queue; }
40 
41  protected:
42  // Internal event handlers.
43  void data_rcvd(satcat5::io::Readable* src) override;
44  void timer_event() override;
45  void wait();
46 
47  // Internal state
50  u8 m_raw[SATCAT5_PIEZO_BUFFER];
51  };
52  }
53 }
ConfigBus core definitions.
Generic ConfigBus API.
Definition: cfgbus_core.h:124
ConfigBus-controlled piezoelectric buzzer.
Definition: cfgbus_piezo.h:27
satcat5::io::PacketBuffer m_queue
Playback queue.
Definition: cfgbus_piezo.h:49
void timer_event() override
Child class MUST override this method.
Definition: cfgbus_piezo.cc:33
satcat5::io::Writeable * queue()
Access the internal playback buffer for writing commands.
Definition: cfgbus_piezo.h:39
Piezo(satcat5::cfg::ConfigBus *cfg, unsigned devaddr, unsigned regaddr=0)
Link this object to the "cfgbus_piezo" control register.
Definition: cfgbus_piezo.cc:10
void flush()
Silence playback and flush internal queue.
Definition: cfgbus_piezo.cc:19
u8 m_raw[SATCAT5_PIEZO_BUFFER]
Raw working buffer.
Definition: cfgbus_piezo.h:50
void data_rcvd(satcat5::io::Readable *src) override
The data_rcvd() callback is polled whenever data is available.
Definition: cfgbus_piezo.cc:26
satcat5::cfg::Register m_reg
Base control register.
Definition: cfgbus_piezo.h:48
Pointer-like wrapper for one or more ConfigBus registers.
Definition: cfgbus_core.h:76
Event-handler interface for newly received data.
Definition: io_readable.h:43
The PacketBuffer class is a wrapper for a circular buffer, with optional logic to support retention o...
Definition: pkt_buffer.h:66
Abstract API for reading byte-streams and packets.
Definition: io_readable.h:68
Abstract API for writing byte-streams and packets.
Definition: io_writeable.h:24
Timer objects are polled after a fixed delay or at a regular interval.
Definition: polling.h:213
Core event-processing loop for SatCat5 software.