Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Digital input management class (mwx::periph_buttons)
Detects changes in digital inputs. This class detects changes when the same detected value is obtained multiple times. This is useful for reducing the effect of chattering on mechanical buttons.
The parameter max_history
is the maximum number of references that can be set with begin()
. Memory is allocated and initialized here.
Starts the Buttons
operation, the first parameter bmPortMask
specifies the bitmap of digital inputs to be monitored. bit 0 corresponds to DIO 0, ... , bit N corresponds to DIO N. More than one can be specified: the second u8HistoryCount
is the number of times required to confirm the value; the third tick_delta
specifies the interval in ms between value checks; the fourth u8HistoryCount
is the number of times to confirm the value.
It will take u8HistoryCount*tick_delta
[ms] to confirm the value. For example, if u8HistoryCount
=5 and tick_delta
=4, it will take at least 20ms to confirm the state.
The confirmation is done in the TickTimer
event handler. Since it is not an interrupt handler, it is affected by delays in processing, etc., but it is sufficient to suppress chattering of mechanical buttons, etc.
Terminates the Buttons
operation.
Returns true
when a change is detected. It is cleared when read()
is executed.
Called when u32port
becomes available. u32portis the bitmap of the current input DIO and
u32changed` is the bitmap of the DIO where the change was detected.
Returns false
if Buttons is not working.
When Buttons starts to operate, the input status of DIO is not yet determined. When the value is determined, it becomes available. At this time, the MSB (bit31) of the bitmap read by read()
is set to 1.
Since this function requires the operation to be determined, it cannot be used to monitor ports whose input values change constantly.
If Buttons is in operation before Sleep, it will resume after it is restored. After resumption, initial determination is performed.
ADC (mwx::periph_analogue.hpp)
Analogue performs ADC and acquires values. It can continuously acquire multiple channels at a time, and can do so sequentially according to a timer or other cycle.
In the standard application (App_Twelite), the pin names ADC2/ADC3 in the semiconductor data sheet are AI3/AI2 to match the TWELITE DIP. Please note this.
*1 ADC2/ADC3 pins for both digital and analog are subject to usage procedures and restrictions.
Assume no pull-up on the pin to be used before the ADC starts. If this is not done, the pull-up voltage will always be observed in the ADC.
In a normal circuit configuration, current leakage occurs during sleep. It cannot be circumvented by software description alone.
To avoid current leakage during sleep, the GND of the analog circuit section should be disconnected with a FET switch or the like and left floating during sleep. Also, before sleep, set the pin to input and pull-up state.
Initializes ADCs. setup() starts the regulator inside the semiconductor, specifies the timer device for periodic execution, and specifies the callback function to be called when all ADCs on the specified channel have completed.
The first parameter specifies the port where the ADC is to be made. The port specification is a bitmap with the bits set corresponding to the port numbers mentioned in the pin definition.For example, if you want to get the values of two pins PIN_ANALOGUE::A2
and PIN_ANALOGUE::VCC
, specify (1 <<PIN_ANALOGUE::A1 | 1<<PIN_ANALOGUE::VCC )
. You can also use pack_bits
and write pack_bits(PIN_ANALOGUE::A1,PIN_ANALOGUE::VCC)
.
After calling begin()
, the first ADC processing starts immediately, and the processing of the next pin starts from its end interrupt. When all processing is finished (if specified), the callback function is called. It waits until the next timer interrupt occurs before starting a new ADC process.
The second parameter specifies the number of timer interrupts before AC starts. For example, TickTimer
is called every 1 ms, but if you specify 16 for the parameter, it will be processed every 16 ms.
Starts ADC processing with default ADC pins (PIN_ANALOGUE::A1
, PIN_ANALOGUE::A2
). end()
resumes the interrupted ADC processing.
ADC processing is terminated and the regulator inside the semiconductor is stopped.
The value of the ADC is set to true
after the acquisition. After confirmation by this function, it is false
until the next ADC completion.
Reads ADC values. The parameter specifies the ADC pin to be read. read()
returns the read value converted to mV and read_raw() returns the ADC value (0..1023).
It is recommended to read Vcc with read()
. This is because a special conversion formula must be applied to convert from read_raw()
values to mV.
After ADC completion (available), if the value is read after a delay until near the timing when the next ADC process is executed, the next ADC value may be returned, because the ADC process is executed by an interrupt handler and the value is updated even during the loop()
process.
The ADC interrupt handler is set to periph_analogue::ADC_handler()
when setup()
is called.
If a different handler is specified by the semiconductor peripheral library, it will not work properly.
If the ADC is in cyclic execution state by begin()
, ADC processing is resumed after returning from sleep.
PulseCounter (mwx::periph_pulse_counter)
The pulse counter is a circuit that reads and counts pulses even when the microcontroller CPU is not running. There are two systems of pulse counters: PC0 is assigned to PulseCounter0
and PC1 to PulseCounter1
.
PC0 is assigned to PulseCounter0
and PC1 is assigned to PulseCounter1
.
Initializes the object and starts counting. the first parameter refct
is the count number on which interrupts and available decisions are based. When this number is exceeded, it is reported to the application. You can also set refct
to 0. In this case, it is not a sleep wake-up factor.
The second parameter edge
specifies whether the interrupt is rising (PIN_INT_MODE::RISING
) or falling (PIN_INT_MODE::FALLING
).
The third debounce
takes the values 0, 1, 2, or 3. 1, 2, or 3 settings require the same consecutive value to detect a change in value to reduce the effect of noise.
Discontinue detection.
If the specified count (refct
in begin()
) is 0, true
is returned when the count exceeds 1.
If the specified count (refct
in begin()
) is 1 or more, true
is returned when the number of detections exceeds the specified count.
Reads the count value. Resets the count value to 0 after reading.
constant | classification | Pin name in standard apps |
---|---|---|
parameter | explanation |
---|---|
setting | number of consecutive samples | maximum detection frequency |
---|
uint8_t PIN_ANALOGUE::A1 = 0
ADC1 pin
AI1
uint8_t PIN_ANALOGUE::A2 = 1
ADC2 pin
AI3
uint8_t PIN_ANALOGUE::A3 = 2
uint8_t PIN_ANALOGUE::D0 = 2
ADC3 pin (DIO0) *1
AI2
uint8_t PIN_ANALOGUE::A4 = 3
uint8_t PIN_ANALOGUE::D1 = 3
ADC4 pin (DIO1) *1
AI4
uint8_t PIN_ANALOGUE::VCC = 4
Vcc Supply voltage
bWaitInit
If true is specified, waits for initialization of the regulator inside the semiconductor.
kick_ev
Specify the timer device to be specified for cyclic execution. The following five types of devices can be specified, and AD is started in the interrupt handler except for the first time.
E_AHI_DEVICE_TICK_TIMER (TickTimer)
E_AHI_DEVICE_TIMER0 .. 4 (Timer0 .. 4)
fp_on_finish
This callback function is called from within the interrupt handler after all ADCs on the specified ports have finished, and is used when ADC measurement values are to be stored separately in a FIFO queue, etc.
| - | 100Khz |
| 2 | 3.7Khz |
| 4 | 2.2Khz |
| 8 | 1.2Khz |
EEPROM
TWELITE Reads and writes to the built-in EEPROM of the wireless microcontroller.
The built-in EEPROM has 3480 bytes available from address 0x000 to 0xEFF.
The first part is Settings (Interactive settings mode), so it is recommended to use the second half of the address when used together. The amount of space consumed by the settings (Interactive settings mode) depends on its implementation. Even with minimal settings, up to 256 bytes are used from the beginning, so use of the later addresses is recommended.
Read the data corresponding to address
from EEPROM.
No error detection.
Write value
from EEPROM to address
.
No error detection.
This function is used when you want to reduce the number of rewrites in consideration of the rewrite life of EEPROM.
Obtain a helper object to read and write using mwx::stream
described below.
stream_helper helper object mwx::stream
operators and methods. Using mwx::stream
, you can read and write integer types such as uint16_t
and uint32_t
types, read and write fixed-length array types such as uint8_t
, and format them using format()
objects.
Interfaces defined in mwx::stream
, such as the <<
operator, can be used on this object.
.seek()
is used to move the EEPROM address to 1024.
The above writes an 8-byte string (00bc614e
), a 4-byte integer (0x12ab34cd
), a 16-byte byte string (HELLO WORLD!....
), and a 1-byte terminating character.
Move the EEPROM address to 1024 using .seek()
.
Reads the data sequence written out earlier. In order, 8-byte characters, 4-byte integers, and 16-byte strings are read out using the >>
operator.
format input parser for serial input (mwx::serial_parser)
This built-in class is defined as a built-in object, intended to be used for format input via serial port.
It is defined as a mwx::serial_parser<mwx::alloc_heap<uint8_t>>
type that allocates buffer space for internal use from the heap at initialization (begin()
).
For details, see class for details.
Read/write two-wire serial (I2C) master (mwx::periph_wire)
Reads and writes two-wire serial (I2C) master.
The mwx::periph_wire<MWX_TWOWIRE_RCVBUFF>
can be referred as TwoWire
.
The following definition types describe the types of arguments and return values.
Some APIs make calls where the STOP bit is not strictly handled.
write(), writer::operator() ()
has several arguments defined in addition to the ones described here.
fixed array type
uint8_t cmds[]={11,12};
...
Wire.write(cmds);
initializer_list<>
型
Wire.write({11,12})
Instance creation and necessary initialization is done in the library. In user code, it is made available by calling Wire.begin()
.
When using the requestFrom()
method, you can specify the size of the FIFO queue for temporary data storage. At compile time, compile the macro MWX_TWOWIRE_BUFF
with the required number of bytes. The default is 32 bytes.
Example:
-DMWX_TWOWIRE_BUFF=16
Initialize hardware.
Performing any Wire operation without initialization will cause the TWELITE radio module to hang.
When waking from sleep, if the module was operating just before sleep, it will return to the previous state.
There are two types of read/write procedures. Select and use one of them.
Member function (input/output using the following member functions)
requestFrom(), beginTransmission(), endTransmission(), write()
Helper class (stream function available)
reader, writer
Checks if the device specified by address
is responding. If the device exists, true
is returned.
The procedure is originally intended to change the bus frequency, but no action is taken.
Parameters | Description |
---|---|
u8mode
Specifies the bus frequency. Default is 100Khz (WIRE_CONF::WIRE_100KHZ
)
The frequency is specified by WIRE_CONF::WIRE_? KHZ
and ? KHZ
can be 50
,66
,80
,100
,133
,160
,200
,266
,320
,400
.
b_portalt
Change hardware pin assignments.
Class Objects
Class objects are predefined objects in the MWX library, such as the_twelite
, which handles TWENET, and objects for using peripherals.
Each object must be initialized by calling the .setup()
or .begin()
method. (Only Serial objects that use UART0 do not require initialization.)