📄 main_option1.c
字号:
}
}
// With full user interface on ATX, user interaction was needed to bring the system up. Therefore: power up
// all units and run the user interface.
// Insert code to start music on audio source here!
adc_wake(); // Wake up ATX resources
if (booterror == 0) { // If no error detected,
if (dac_wake() != OKAY) { // Try to wake up DAC
booterror = 1; // If that failed, stop bootup code
}
}
if (booterror == 0) { // If no error detected,
if (z1_arx_mute(MUTEOFF) != OKAY) { // Try to unmute ARX
muted = 0; // Simulate play/pause button
booterror = 1; // If that failed, stop bootup code
}
}
// After starting up all subcircuits, the devices are on. This is indicated to the CPU as powermode == PMODE_AWAKE.
// In this mode, the sleep enable bits in RXMOD and TXMOD are cleared. Also, TXWTI and RXWTI are set to != 0x00 to
// enable automatic power down. In RXMOD, the sleep enable bit was set in EEPROM (see top of file) and never cleared
// in the program. But the power down bit in TXMOD was set in EEPROM and set upon exiting the link finding loop
// above. However, TXWTI was never reset to enable auto power down, so this must be done now:
z1_singlewrite(TXWTI, SLEEP_TXWTI); // Reset TXWTI, ATX auto power down is enabled in PMODE_AWAKE
#ifdef USELED
ledsequence = LED_AWAKE; // Blink in a pattern indicating audio streaming
#endif
powermode = PMODE_AWAKE; // And indicate a power up of ATX
// Run product interface by polling buttons on TX and RX unit
while (booterror == 0) {
// Buttons on ARX are hardwired to GPI pins DI[0:3] or written into RXPIN on ARX according to the table
// in hpref_defines.h. Buttons on ATX are translated in mcu_xxxx.c from the actual hardware I/O pins on the MCU
// to a key code equal to the hardware key codes defined for ARX. The key codes are then processed in
// this file. All buttons on DI[0:3] are active high. Key codes comprising more than one high bit must
// be generated by an ARX MCU or diode network. Unused ARX DI[0:3] pins must be tied to ground.
// This part of the MCU program uses key polling and a low-power wait state.
if (powermode == PMODE_AUTODOWN) // Auto power down was detected. Poll interrupt bit for power up
mcu_wait_ms(320);
else if (powermode == PMODE_POWERDOWN) // Controlled power down, MCU timer is used to poll Play button on
mcu_wait_ms(320); // MCU. If Play is pressed, the MCU brings the system out of power down
if (powermode == PMODE_AWAKE) // Audio streaming mode, MCU polls for input from user interface
mcu_wait_ms(64);
// There are six combinations of variables powermode and wakeup. These six combinations are summarized below.
//// USER INTERFACE OPTION 1 //// ATX is wake-on-interrupt, ARX is wake-on-timer
// | powermode == | powermode == | powermode ==
// | PMODE_AUTODOWN | PMODE_POWERDOWN | PMODE_AWAKE
// | | |
// wakeup == | Check if Play | No ATX interrupts | ATX interrupts
// WAKE_Z1_INT | button is pressed | this state makes | this state makes
// | on ATX. If it is, | no sense | no sense
// | try to set up link | |
// wakeup == | w/semi-fast polling | Check Play button to | Audio streaming mode,
// WAKE_WAIT | in MCU | exit sleep mode | MCU polls user interfaces
if (powermode == PMODE_AUTODOWN) {
// It was detected that nRF24Z1 went to auto power down. Only the MCU timer will wake up the MCU in user
// interface option 1. When going to auto power down, both TXMOD anr RXMOD were set for audio streaming.
// Therefore there is no need to clear the sleep enable bits in TXMOD and RXMOD when exiting auto power down.
// ATX is wake-on-interrupt, check if user is pressing Play on ATX
buttons = mcu_buttons(); // Read buttons on local MCU GPIO pins
if (buttons == BTN_PLAY) { // If Play button was pressed, wake up system by:
mcu_z1wakeup_pin(); // Toggle the pin that wakes up ATX nRF24Z1 from wake-on-interrupt, ATX then awake TXWTI(TXLTI+1)10ms
if (z1_haslink_wait()) { // Check for link a number of times, if success:
// Instruct your audio source to commence playing music here!
adc_wake(); // Wake up ATX resources
dac_wake(); // Wake up ARX resources, may also test that logical return of dac_wake() indicated success
z1_arx_mute(MUTEOFF); // If ARX was muted at by pause button remove muting each time units exit sleep mode by UI
muted = 0; // Simulating Play/Pause functionality
#ifdef USELED
ledsequence = LED_AWAKE; // Blink in a pattern indicating audio streaming
#endif
powermode = PMODE_AWAKE; // And indicate a power up of ATX
}
}
#ifdef USELED
mcu_atxled(z1_rotate_led()); // Alter ATX LED according to blinking sequence, after potentially critical operations!
#endif
} // powermode == PMODE_AUTODOWN
else if (powermode == PMODE_POWERDOWN) {
if (wakeup == WAKE_Z1_INT) {
// In user interface option 1 the ATX nRF24Z1 does not generate any interrupts to the MCU while in sleep mode.
// That is because it sleeps until it receives an interrupt from the MCU. We are not supposed to receive
// any interrupts from sleeping ATX nRF24Z1. Exception is when ARX nRF24Z1 has just received a wakeup interrupt
// from the MCU.
#ifdef TERMINATE_ON_ERROR
booterror = 1;
#endif
} // PMODE_POWERDOWN / WAKE_Z1_INT
else if (wakeup == WAKE_WAIT) {
// In user interface option 1 the ATX is wake-on-interrupt (it wakes on an interrupt
// generated by the MCU). It is therefore not able to interrupt the MCU on its own, and the MCU must
// instead use polling (i.e. its internal timer is used for polling, not as a safety measure).
// Poll ATX Play button and bring system out of sleep mode if it is being pressed
buttons = mcu_buttons(); // Read buttons from local MCU only
if (buttons == BTN_PLAY) { // Play button will wake system
mcu_z1wakeup_pin(); // Toggle the pin that wakes up ATX nRF24Z1 from wake-on-interrupt
z1_singlewrite(TXWTI, 0x00); // Disable auto power down while sending wakeup commands to ATX
z1_singlewrite(TXMOD, z1_singleread(TXMOD) & ~0x40); // Wake up ATX
z1_singlewrite(RXMOD, z1_singleread(RXMOD) & ~0x80); // Wake up ARX
// In user interface option 1, the ARX is wake-on-timer operating on a slow clock. If the user presses the ATX
// Play button while the ARX is out of range, no link is established, and the system should go back to the sleep
// mode it was in, PMODE_POWERDOWN.
if (z1_haslink_wait()) { // Wait until a link is established or timeout
// Instruct source to commence playing music
adc_wake(); // Wake up ATX resources
dac_wake(); // Wake up ARX resources, may also test that logical return of dac_wake() indicated success
z1_arx_mute(MUTEOFF); // If ARX was muted at by pause button remove muting each time units exit sleep mode by UI
muted = 0; // Simulating Play/Pause functionality
#ifdef USELED
ledsequence = LED_AWAKE;// Blink in a pattern indicating audio streaming
#endif
powermode = PMODE_AWAKE; // Indicate that system is awake
debounce = 1; // Activate software debounce
z1_singlewrite(TXWTI, SLEEP_TXWTI); // Re-enable auto power down = allow for proper TXLTI timing
}
else { // No link found, power things down again, this is same sequence as Stop button performs
z1_singlewrite(RXMOD, z1_singleread(RXMOD) | 0x80); // Put ARX to sleep
z1_singlewrite(TXWTI, SLEEP_TXWTI); // Re-enable auto power down = allow for proper TXLTI timing
z1_singlewrite(TXMOD, z1_singleread(TXMOD) | 0x40); // Put ATX to sleep
} // No link found
} // BTN_PLAY
#ifdef USELED
mcu_atxled(z1_rotate_led()); // Alter ATX LED according to blinking sequence, after potentially critical operations!
#endif
} // PMODE_POWERDOWN / WAKE_WAIT
}
else if (powermode == PMODE_AWAKE) {
if (wakeup == WAKE_Z1_INT) {
// In user interface option 1 the ATX nRF24Z1 will not start generating interrupts to the MCU if it goes to
// auto power down mode. Instead, its IRQ output will be static at "1" (because the interrupt to the MCU is active low).
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -