Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Functions
System functions (time, random numbers)
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
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.
constant | classification | Pin name in standard apps |
---|---|---|
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.
parameter | explanation |
---|---|
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.
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.)
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 serparser for details.
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.
system timer (mwx::periph_ticktimer)
TickTimer is used for internal control of TWENET and is implicitly executed. The period of the timer is 1ms. Only the available()
method is defined in loop()
for the purpose of describing processing every 1ms by the TickTimer event.
Note that it is not always available in 1ms increments.
There are cases in which events are skipped due to a large delay caused by factors such as the contents of the user program description or the system's internal interrupt processing.
available()
It is set after the TickTimer interrupt occurs and becomes true
in the loop()
immediately following it. It is cleared after loop()
ends.
SPI access (using helper class)
The helper class version is a more abstract implementation. Creating a transceiver
object for reading and writing is the start of using the bus, and destroying the object is the end of using the bus.
By creating the object in the decision expression of the if statement, the validity period of the object is limited to the scope of the if clause, and the object is destroyed when it exits the if clause, at which point the bus usage termination procedure is performed.
In addition, read/write objects implement the mwx::stream
interface, allowing the use of the <<
operator, etc.
The start and end of bus usage is aligned with the validity period of the object to improve the visibility of the source code and to prevent omissions in the termination procedure, etc.
Unify read/write procedures with the mwx::stream
interface
Reading process and its termination procedure in scope if() { ... }
to do the reading with a helper class.
In the above, the x
object created by the get_rwer()
method is used to read and write one byte at a time. 1.
create x
object in if(...)
Generate the x
object in the get_rwer()
method. At the same time, set the select pin of the SPI bus. (The type is resolved with the universal reference auto&&
by type inference. 2.)
the generated x
object has a operator bool ()
defined, which is used to evaluate the decision expression, which is always true
for the SPI bus.
x
object defines uint8_t transfer(uint8_t)
method, which is called to perform 8bit read/write transfer to SPI. 4. 4.if() { ... }
Destructor of x
is called at the end of the scope to release the select pin of the SPI bus.
Obtains the worker object used to read/write the SPI bus.
Each transfers 8-bit, 16-bit, and 32-bit data, and returns the read result with the same data width as the written data width.
The int
and uint8_t
types perform 8-bit transfer.
Types uint16_t
and uint32_t
perform 16-bit and 32-bit transfers, respectively.
The transfer result is stored in an internal FIFO queue of up to 16 bytes and read by the >>
operator. Since the buffer is not large, it is assumed to be read out after each transfer.
Specify a variable with the same data width as the previous transfer.
If the result of the read is not needed, use the null_stream() object; it skips reading by the data byte specified by i. If the result of the read is not needed, use the null_stream() object.
The core class object of TWENET (mwx::twenet)
The the_twelite
object summarizes the procedures for using TWENET and includes procedures for operating the wireless microcontroller, such as basic wireless settings, sleep, and other procedures.
the_twelite
is set up in the setup()
function, which also calls the_twelite.begin()
to start the process. It is not possible to set up the_twelite
except in setup()
.
In the above example, the application ID is set, the communication channel is set, and the receiving circuit is set.
Various procedures are included.
It is also possible to register classes that handle wireless networks, classes that summarize board support, and classes that perform event-driven processing described by the user. By registering these classes, dedicated functions can be easily used. These classes are referred to as "behaviors" in this explanation.
In the above example, two types of behaviors are registered: environmental sensor pal behavior <PAL_AMB>
and simple relay network <NWK_SIMPLE>
. By registering these, hardware such as sensors on the environmental sensor pal can be easily handled. In addition, the complicated handling of wireless packets can be implicitly provided with functions such as relay processing and automatic discarding of duplicate packet arrivals.
The MWX library defines other methods in addition to those introduced here.
Act descriptions include those that are not directly related to the act description, those that are set up but do not function effectively, and those that are used internally.
<<operator
(setting)The <<
operator is used to initialize the object the_twelite
.
The following configuration class objects are used as input, and default values are applied if no configuration is made.
Set the parameter id
to the specified application ID. This is a required specification.
Reading the settings is done with uint32_t the_twelite.get_appid()
.
Set the specified channel number (11
..26
) in parameter ch
.
Reading the settings is done with uint8_t
the_twelite.get_channel()
.
Parameter pw
is set to (0
. 3
) for the radio output. The default is (3: no output attenuation).
Reading the settings is done with uint8_t the_twelite.get_tx_power()
.
If the parameter bEnable
is 1
, the receiver circuit is always activated and can receive radio packets from others. The default is 0
, which is dedicated to transmission only.
Reading the settings is done with uint8_t the_twelite.get_rx_when_idle()
.
Enables the channel manager. If multiple channels are specified, sending/receiving is performed on multiple channels; if 0 is specified for ch2 and ch3, the specification is disabled.
Reflects the setting values in interactive mode.
The items that will be reflected are as follows
app_id
channel
tx_power
Number of retransmissions when MAC ack is used
There are other settings in the MWX library code that are irrelevant to the library's functionality at this time or that may cause conflicts if set.
It is executed after preconfiguration (see <<
operator) and registration of the behavior. It is usually placed at the end of the setup()
function.
the_twelite
finished setting up
Behavior initialization
TWENET initialization is also performed after the setup()
function exits. Since many processes are to be executed after setup()
exits, do not do anything other than initialization here.
Changes channel settings. On failure, the channel is not changed and false
is returned.
Obtains the currently set channel number (11..26) from the MAC layer API.
Get the module serial number.