diff --git a/receivers/native/arduino/src/main/c++/arduino-converter-files/ZscriptDefaultParameters.hpp b/receivers/native/arduino/src/main/c++/arduino-converter-files/ZscriptDefaultParameters.hpp index c60b063ae..5e44587bc 100644 --- a/receivers/native/arduino/src/main/c++/arduino-converter-files/ZscriptDefaultParameters.hpp +++ b/receivers/native/arduino/src/main/c++/arduino-converter-files/ZscriptDefaultParameters.hpp @@ -30,7 +30,7 @@ //#define ZSCRIPT_PIN_SUPPORT_NOTIFICATIONS //#define ZSCRIPT_PIN_SUPPORT_ANALOG_NOTIFICATIONS -//#define ZSCRIPT_HAVE_I2C_MODULE +//#define ZSCRIPT_HAVE_I2C_GENERAL //#define ZSCRIPT_HAVE_I2C_CHANNEL //#define ZSCRIPT_I2C_SUPPORT_NOTIFICATIONS diff --git a/receivers/native/arduino/src/main/c++/arduino-converter-files/ZscriptFullInclude.hpp b/receivers/native/arduino/src/main/c++/arduino-converter-files/ZscriptFullInclude.hpp index 852528b63..ec6dccf71 100644 --- a/receivers/native/arduino/src/main/c++/arduino-converter-files/ZscriptFullInclude.hpp +++ b/receivers/native/arduino/src/main/c++/arduino-converter-files/ZscriptFullInclude.hpp @@ -24,9 +24,7 @@ #include "arduino/pins-module/PinModule.hpp" #endif -#if defined(ZSCRIPT_HAVE_I2C_MODULE) || defined(ZSCRIPT_HAVE_I2C_CHANNEL) - #include "arduino/i2c-module/I2cModule.hpp" -#endif +#include "arduino/i2c-module/I2cModule_all.hpp" #if defined(ZSCRIPT_HAVE_UART_MODULE) || defined(ZSCRIPT_HAVE_UART_CHANNEL) @@ -47,9 +45,7 @@ // INCLUDE ALL CHANNELS BELOW HERE! -#if defined(ZSCRIPT_HAVE_I2C_CHANNEL) - #include -#endif +#include #if defined(ZSCRIPT_HAVE_UART_CHANNEL) #include "arduino/uart-module/channels/UartChannel.hpp" @@ -127,7 +123,7 @@ class ArduinoZscriptBasicSetup { Zscript::servo_module::ZscriptServoModule::setup(); #endif uint8_t i = 0; -#if defined(ZSCRIPT_HAVE_I2C_MODULE) || defined(ZSCRIPT_HAVE_I2C_CHANNEL) +#if defined(ZSCRIPT_HAVE_I2C_GENERAL) || defined(ZSCRIPT_HAVE_I2C_CHANNEL) Zscript::i2c_module::I2cModule::setup(); #endif #if defined(ZSCRIPT_HAVE_I2C_CHANNEL) diff --git a/receivers/native/arduino/src/main/c++/arduino/arduino-core-module/commands/ZscriptResetCommand.hpp b/receivers/native/arduino/src/main/c++/arduino/arduino-core-module/commands/ZscriptResetCommand.hpp index 9f9218234..de93bcec4 100644 --- a/receivers/native/arduino/src/main/c++/arduino/arduino-core-module/commands/ZscriptResetCommand.hpp +++ b/receivers/native/arduino/src/main/c++/arduino/arduino-core-module/commands/ZscriptResetCommand.hpp @@ -5,8 +5,10 @@ * SPDX-License-Identifier: MIT */ -#ifndef SRC_MAIN_CPP_ARDUINO_ARDUINO_CORE_MODULE_COMMANDS_ZSCRIPTRESETCOMMAND_HPP_ -#define SRC_MAIN_CPP_ARDUINO_ARDUINO_CORE_MODULE_COMMANDS_ZSCRIPTRESETCOMMAND_HPP_ +#if defined(SRC_ZSCRIPT_BASE_RESET_COMMAND) +#error This file should not be included more than once +#endif +#define SRC_ZSCRIPT_BASE_RESET_COMMAND #include #include @@ -32,4 +34,3 @@ class ZscriptResetCommand: public Reset_CommandDefs { #define ZSCRIPT_RESET_COMMAND -#endif /* SRC_MAIN_CPP_ARDUINO_ARDUINO_CORE_MODULE_COMMANDS_ZSCRIPTRESETCOMMAND_HPP_ */ diff --git a/receivers/native/arduino/src/main/c++/arduino/i2c-module/I2cManager.hpp b/receivers/native/arduino/src/main/c++/arduino/i2c-module/I2cManager.hpp deleted file mode 100644 index 20f66c75f..000000000 --- a/receivers/native/arduino/src/main/c++/arduino/i2c-module/I2cManager.hpp +++ /dev/null @@ -1,52 +0,0 @@ -/* - * Zscript Library - Command System for Microcontrollers) - * Copyright (c) 2022 Zscript team (Susan Witts, Alicia Witts) - * - * SPDX-License-Identifier: MIT - */ - -#ifndef SRC_MAIN_C___ARDUINO_I2C_MODULE_I2CMANAGER_HPP_ -#define SRC_MAIN_C___ARDUINO_I2C_MODULE_I2CMANAGER_HPP_ - -#ifndef I2C_ADDRESS_AND_GENERAL_CALL -#if defined(__AVR__) -#define I2C_ADDRESS_AND_GENERAL_CALL(addr) do { TWAR = (addr<<1) | 1; } while(0) -#elif defined(ARDUINO_ARCH_NRF52840) -#define I2C_ADDRESS_AND_GENERAL_CALL(addr) do { NRF_TWIS0->ADDRESS[0] = addr; NRF_TWIS0->ADDRESS[1] = 0; NRF_TWIS0->CONFIG = 0x3; } while(0) -#else -#error "Unknown board, cannot implement I2C address set outside of wire library, so cannot use I2C Channel" -#endif -#endif - -#ifndef I2C_BEGIN_SMBUS_ALERT -#if defined(__AVR__) -#define I2C_BEGIN_SMBUS_ALERT() do { TWAR = (0xC<<1) | 1; } while(0) -#elif defined(ARDUINO_ARCH_NRF52840) -#define I2C_BEGIN_SMBUS_ALERT(addr) do { NRF_TWIS0->ADDRESS[1] = 0xC; } while(0) -#else -#error "Unknown board, cannot implement I2C address set outside of wire library, so cannot use I2C Channel" -#endif -#endif - -#ifndef I2C_END_SMBUS_ALERT -#if defined(__AVR__) -#define I2C_END_SMBUS_ALERT(addr) do { TWAR = (addr<<1) | 1; } while(0) -#elif defined(ARDUINO_ARCH_NRF52840) -#define I2C_END_SMBUS_ALERT(addr) do { NRF_TWIS0->ADDRESS[1] = 0x0; } while(0) -#else -#error "Unknown board, cannot implement I2C address set outside of wire library, so cannot use I2C Channel" -#endif -#endif - -#ifndef I2C_WAS_SMBUS_ALERT_READ -#if defined(__AVR__) -#define I2C_WAS_SMBUS_ALERT_READ() true -#elif defined(ARDUINO_ARCH_NRF52840) -#define I2C_WAS_SMBUS_ALERT_READ() (NRF_TWIS0->MATCH == 1) -#else -#error "Unknown board, cannot implement I2C address set outside of wire library, so cannot use I2C Channel" -#endif -#endif - - -#endif /* SRC_MAIN_C___ARDUINO_I2C_MODULE_I2CMANAGER_HPP_ */ diff --git a/receivers/native/arduino/src/main/c++/arduino/i2c-module/I2cModule.hpp b/receivers/native/arduino/src/main/c++/arduino/i2c-module/I2cModule_all.hpp similarity index 61% rename from receivers/native/arduino/src/main/c++/arduino/i2c-module/I2cModule.hpp rename to receivers/native/arduino/src/main/c++/arduino/i2c-module/I2cModule_all.hpp index 1b78ef80f..76d1a7377 100644 --- a/receivers/native/arduino/src/main/c++/arduino/i2c-module/I2cModule.hpp +++ b/receivers/native/arduino/src/main/c++/arduino/i2c-module/I2cModule_all.hpp @@ -5,64 +5,50 @@ * SPDX-License-Identifier: MIT */ -#ifndef SRC_MAIN_CPP_ARDUINO_I2C_MODULE_ZSCRIPTI2CMODULE_HPP_ -#define SRC_MAIN_CPP_ARDUINO_I2C_MODULE_ZSCRIPTI2CMODULE_HPP_ - - -#ifdef ZSCRIPT_I2C_SUPPORT_NOTIFICATIONS - #define ZSCRIPT_HAVE_I2C_MODULE -#endif - -#include -#include - -#if defined(ZSCRIPT_I2C_SUPPORT_NOTIFICATIONS) - #if defined(ZSCRIPT_SUPPORT_ADDRESSING) - #include - #endif - - #if defined(ZSCRIPT_SUPPORT_NOTIFICATIONS) - #include - #include - #include "notifications/I2cNotification.hpp" - #endif -#endif - -#if defined(ZSCRIPT_HAVE_I2C_CHANNEL) - #include "commands/I2cChannelInfo.hpp" - #include "commands/I2cChannelSetup.hpp" -#endif - -#if defined(ZSCRIPT_HAVE_I2C_MODULE) - #include "commands/I2cSetupCommand.hpp" - #include "commands/GeneralI2cAction.hpp" +#if defined(SRC_ZSCRIPT_BASE_I2C_MODULE) + #error I2C Module definition should not be included more than once #endif - -#include "commands/I2cCapabilitiesCommand.hpp" +#define SRC_ZSCRIPT_BASE_I2C_MODULE #ifdef ZSCRIPT_HPP_INCLUDED #error Must be included before Zscript.hpp #endif +#include +#include +#include + #define MODULE_EXISTS_005 EXISTENCE_MARKER_UTIL #define MODULE_SWITCH_005 MODULE_SWITCH_UTIL(i2c_module::I2cModule::execute) -#if defined(ZSCRIPT_I2C_SUPPORT_NOTIFICATIONS) - #if defined(ZSCRIPT_SUPPORT_ADDRESSING) - #define MODULE_ADDRESS_EXISTS_005 EXISTENCE_MARKER_UTIL - #define MODULE_ADDRESS_SWITCH_005 ADDRESS_SWITCH_UTIL(i2c_module::I2cModule::address) - #endif +// Notifications +#include + #define MODULE_NOTIFICATION_EXISTS_005 EXISTENCE_MARKER_UTIL #define MODULE_NOTIFICATION_SWITCH_005 NOTIFICATION_SWITCH_UTIL(i2c_module::I2cModule::notification) + +// Addressing +#if defined(ZSCRIPT_SUPPORT_ADDRESSING) + #include + #define MODULE_ADDRESS_EXISTS_005 EXISTENCE_MARKER_UTIL + #define MODULE_ADDRESS_SWITCH_005 ADDRESS_SWITCH_UTIL(i2c_module::I2cModule::address) #endif +// Channel commands +#include +#include + +// General commands +#include +#include +#include + namespace Zscript { namespace i2c_module { template class I2cModule : public ZscriptModule { -#if defined(ZSCRIPT_I2C_SUPPORT_NOTIFICATIONS) static bool isAddressing; static bool giveNotifs; @@ -72,38 +58,23 @@ class I2cModule : public ZscriptModule { } } -#endif - public: -#if defined(ZSCRIPT_HAVE_I2C_CHANNEL) static I2cChannel channel; -#endif - - -#if defined(ZSCRIPT_I2C_SUPPORT_NOTIFICATIONS) static GenericCore::ZscriptNotificationSource notifSrc; -#endif static void setup() { -#if defined(ZSCRIPT_I2C_SUPPORT_NOTIFICATIONS) pinMode(ZP::i2cAlertInPin, INPUT_PULLUP); attachInterrupt(digitalPinToInterrupt(ZP::i2cAlertInPin), &smBusAlertReceived, FALLING); pinMode(ZP::i2cAlertInPin, INPUT_PULLUP); -#endif -#if defined(ZSCRIPT_HAVE_I2C_CHANNEL) + channel.setup(); channel.setAddress(ZscriptParams::i2cChannelAddress); -#else - Wire.begin(); -#endif } static void poll() { -#if defined(ZSCRIPT_I2C_SUPPORT_NOTIFICATIONS) if (digitalRead(ZP::i2cAlertInPin) == LOW) { smBusAlertReceived(); } -#endif } static void execute(ZscriptCommandContext ctx, uint8_t bottomBits) { @@ -111,14 +82,8 @@ class I2cModule : public ZscriptModule { case ZscriptI2cCapabilitiesCommand::CODE: ZscriptI2cCapabilitiesCommand::execute(ctx, MODULE_CAPABILITIES(005)); break; -#if defined(ZSCRIPT_HAVE_I2C_MODULE) case ZscriptI2cSetupCommand::CODE: - ZscriptI2cSetupCommand::execute(ctx - -#if defined(ZSCRIPT_I2C_SUPPORT_NOTIFICATIONS) - , &isAddressing, &giveNotifs -#endif - ); + ZscriptI2cSetupCommand::execute(ctx, &isAddressing, &giveNotifs); break; case GeneralI2cAction::SEND_CODE: GeneralI2cAction::executeSendReceive(ctx, GeneralI2cAction::ActionType::SEND); @@ -129,23 +94,19 @@ class I2cModule : public ZscriptModule { case GeneralI2cAction::SEND_RECEIVE_CODE: GeneralI2cAction::executeSendReceive(ctx, GeneralI2cAction::ActionType::SEND_RECEIVE); break; -#endif -#if defined(ZSCRIPT_HAVE_I2C_CHANNEL) case ZscriptI2cChannelInfoCommand::CODE: ZscriptI2cChannelInfoCommand::execute(ctx); break; case ZscriptI2cChannelSetupCommand::CODE: ZscriptI2cChannelSetupCommand::execute(ctx); break; -#endif default: ctx.status(ResponseStatus::COMMAND_NOT_FOUND); break; } } -#if defined(ZSCRIPT_I2C_SUPPORT_NOTIFICATIONS) - #if defined(ZSCRIPT_SUPPORT_ADDRESSING) +#if defined(ZSCRIPT_SUPPORT_ADDRESSING) static void address(ZscriptAddressingContext ctx) { if (!isAddressing) { ctx.status(ResponseStatus::ADDRESS_NOT_FOUND); @@ -153,20 +114,16 @@ class I2cModule : public ZscriptModule { } GeneralI2cAction::executeAddressing(ctx); } - #endif +#endif static void notification(ZscriptNotificationContext ctx, bool moveAlong) { ZscriptI2cNotification::notification(ctx, moveAlong, isAddressing); } -#endif }; -#if defined(ZSCRIPT_HAVE_I2C_CHANNEL) template I2cChannel I2cModule::channel; -#endif -#if defined(ZSCRIPT_I2C_SUPPORT_NOTIFICATIONS) template bool I2cModule::isAddressing = false; @@ -175,9 +132,8 @@ bool I2cModule::giveNotifs = false; template GenericCore::ZscriptNotificationSource I2cModule::notifSrc; -#endif + } } -#endif /* SRC_MAIN_CPP_ARDUINO_I2C_MODULE_ZSCRIPTI2CMODULE_HPP_ */ diff --git a/receivers/native/arduino/src/main/c++/arduino/i2c-module/I2cModule_channelGeneral.hpp b/receivers/native/arduino/src/main/c++/arduino/i2c-module/I2cModule_channelGeneral.hpp new file mode 100644 index 000000000..2220dc0eb --- /dev/null +++ b/receivers/native/arduino/src/main/c++/arduino/i2c-module/I2cModule_channelGeneral.hpp @@ -0,0 +1,89 @@ +/* + * Zscript Library - Command System for Microcontrollers) + * Copyright (c) 2022 Zscript team (Susan Witts, Alicia Witts) + * + * SPDX-License-Identifier: MIT + */ + +#if defined(SRC_ZSCRIPT_BASE_I2C_MODULE) + #error This file should not be included more than once +#endif +#define SRC_ZSCRIPT_BASE_I2C_MODULE + +#ifdef ZSCRIPT_HPP_INCLUDED + #error Must be included before Zscript.hpp +#endif + +#include + +#include +#include + +#define MODULE_EXISTS_005 EXISTENCE_MARKER_UTIL +#define MODULE_SWITCH_005 MODULE_SWITCH_UTIL(i2c_module::I2cModule::execute) + +// Channel +#include +#include + +// All +#include +#include +#include + +namespace Zscript { + +namespace i2c_module { + +template +class I2cModule : public ZscriptModule { +public: + static I2cChannel channel; + + static void setup() { + channel.setup(); + channel.setAddress(ZscriptParams::i2cChannelAddress); + } + + static void poll() { + } + + static void execute(ZscriptCommandContext ctx, uint8_t bottomBits) { + switch (bottomBits) { + case ZscriptI2cCapabilitiesCommand::CODE: + ZscriptI2cCapabilitiesCommand::execute(ctx, MODULE_CAPABILITIES(005)); + break; + case ZscriptI2cSetupCommand::CODE: + ZscriptI2cSetupCommand::execute(ctx); + break; + case GeneralI2cAction::SEND_CODE: + GeneralI2cAction::executeSendReceive(ctx, GeneralI2cAction::ActionType::SEND); + break; + case GeneralI2cAction::RECEIVE_CODE: + GeneralI2cAction::executeSendReceive(ctx, GeneralI2cAction::ActionType::RECEIVE); + break; + case GeneralI2cAction::SEND_RECEIVE_CODE: + GeneralI2cAction::executeSendReceive(ctx, GeneralI2cAction::ActionType::SEND_RECEIVE); + break; + case ZscriptI2cChannelInfoCommand::CODE: + ZscriptI2cChannelInfoCommand::execute(ctx); + break; + case ZscriptI2cChannelSetupCommand::CODE: + ZscriptI2cChannelSetupCommand::execute(ctx); + break; + default: + ctx.status(ResponseStatus::COMMAND_NOT_FOUND); + break; + } + } +}; + +#if defined(ZSCRIPT_HAVE_I2C_CHANNEL) +template +I2cChannel I2cModule::channel; +#endif + +} + +} + diff --git a/receivers/native/arduino/src/main/c++/arduino/i2c-module/I2cModule_channelOnly.hpp b/receivers/native/arduino/src/main/c++/arduino/i2c-module/I2cModule_channelOnly.hpp new file mode 100644 index 000000000..45ec7a754 --- /dev/null +++ b/receivers/native/arduino/src/main/c++/arduino/i2c-module/I2cModule_channelOnly.hpp @@ -0,0 +1,79 @@ +/* + * Zscript Library - Command System for Microcontrollers) + * Copyright (c) 2022 Zscript team (Susan Witts, Alicia Witts) + * + * SPDX-License-Identifier: MIT + */ + +#if defined(SRC_ZSCRIPT_BASE_I2C_MODULE) + #error This file should not be included more than once +#endif +#define SRC_ZSCRIPT_BASE_I2C_MODULE + +#ifdef ZSCRIPT_HPP_INCLUDED + #error Must be included before Zscript.hpp +#endif + +#include + +#include +#include + +#define MODULE_EXISTS_005 EXISTENCE_MARKER_UTIL +#define MODULE_SWITCH_005 MODULE_SWITCH_UTIL(i2c_module::I2cModule::execute) + +// Channel +#include +#include + +// All +#include + +namespace Zscript { + +namespace i2c_module { + +template +class I2cModule : public ZscriptModule { +public: + static I2cChannel channel; + + + static void setup() { + channel.setup(); + channel.setAddress(ZscriptParams::i2cChannelAddress); + } + + static void poll() { +#if defined(ZSCRIPT_I2C_SUPPORT_NOTIFICATIONS) + if (digitalRead(ZP::i2cAlertInPin) == LOW) { + smBusAlertReceived(); + } +#endif + } + + static void execute(ZscriptCommandContext ctx, uint8_t bottomBits) { + switch (bottomBits) { + case ZscriptI2cCapabilitiesCommand::CODE: + ZscriptI2cCapabilitiesCommand::execute(ctx, MODULE_CAPABILITIES(005)); + break; + case ZscriptI2cChannelInfoCommand::CODE: + ZscriptI2cChannelInfoCommand::execute(ctx); + break; + case ZscriptI2cChannelSetupCommand::CODE: + ZscriptI2cChannelSetupCommand::execute(ctx); + break; + default: + ctx.status(ResponseStatus::COMMAND_NOT_FOUND); + break; + } + } +}; + +template +I2cChannel I2cModule::channel; + +} + +} + diff --git a/receivers/native/arduino/src/main/c++/arduino/i2c-module/I2cModule_general.hpp b/receivers/native/arduino/src/main/c++/arduino/i2c-module/I2cModule_general.hpp new file mode 100644 index 000000000..7ebc54bdc --- /dev/null +++ b/receivers/native/arduino/src/main/c++/arduino/i2c-module/I2cModule_general.hpp @@ -0,0 +1,70 @@ +/* + * Zscript Library - Command System for Microcontrollers) + * Copyright (c) 2022 Zscript team (Susan Witts, Alicia Witts) + * + * SPDX-License-Identifier: MIT + */ + +#if defined(SRC_ZSCRIPT_BASE_I2C_MODULE) + #error This file should not be included more than once +#endif +#define SRC_ZSCRIPT_BASE_I2C_MODULE + +#ifdef ZSCRIPT_HPP_INCLUDED + #error Must be included before Zscript.hpp +#endif + +#include + +#include +#include + +#define MODULE_EXISTS_005 EXISTENCE_MARKER_UTIL +#define MODULE_SWITCH_005 MODULE_SWITCH_UTIL(i2c_module::I2cModule::execute) + +// All +#include +#include +#include + +namespace Zscript { + +namespace i2c_module { + +template +class I2cModule : public ZscriptModule { +public: + static void setup() { + Wire.begin(); + } + + static void poll() { + } + + static void execute(ZscriptCommandContext ctx, uint8_t bottomBits) { + switch (bottomBits) { + case ZscriptI2cCapabilitiesCommand::CODE: + ZscriptI2cCapabilitiesCommand::execute(ctx, MODULE_CAPABILITIES(005)); + break; + case ZscriptI2cSetupCommand::CODE: + ZscriptI2cSetupCommand::execute(ctx); + break; + case GeneralI2cAction::SEND_CODE: + GeneralI2cAction::executeSendReceive(ctx, GeneralI2cAction::ActionType::SEND); + break; + case GeneralI2cAction::RECEIVE_CODE: + GeneralI2cAction::executeSendReceive(ctx, GeneralI2cAction::ActionType::RECEIVE); + break; + case GeneralI2cAction::SEND_RECEIVE_CODE: + GeneralI2cAction::executeSendReceive(ctx, GeneralI2cAction::ActionType::SEND_RECEIVE); + break; + default: + ctx.status(ResponseStatus::COMMAND_NOT_FOUND); + break; + } + } +}; +} + +} + diff --git a/receivers/native/arduino/src/main/c++/arduino/i2c-module/I2cModule_notifications.hpp b/receivers/native/arduino/src/main/c++/arduino/i2c-module/I2cModule_notifications.hpp new file mode 100644 index 000000000..c98a562b8 --- /dev/null +++ b/receivers/native/arduino/src/main/c++/arduino/i2c-module/I2cModule_notifications.hpp @@ -0,0 +1,122 @@ +/* + * Zscript Library - Command System for Microcontrollers) + * Copyright (c) 2022 Zscript team (Susan Witts, Alicia Witts) + * + * SPDX-License-Identifier: MIT + */ + +#if defined(SRC_ZSCRIPT_BASE_I2C_MODULE) + #error This file should not be included more than once +#endif +#define SRC_ZSCRIPT_BASE_I2C_MODULE + +#ifdef ZSCRIPT_HPP_INCLUDED + #error Must be included before Zscript.hpp +#endif + +#include + +#include +#include + +#define MODULE_EXISTS_005 EXISTENCE_MARKER_UTIL +#define MODULE_SWITCH_005 MODULE_SWITCH_UTIL(i2c_module::I2cModule::execute) + +// Notifications +#include + +#define MODULE_NOTIFICATION_EXISTS_005 EXISTENCE_MARKER_UTIL +#define MODULE_NOTIFICATION_SWITCH_005 NOTIFICATION_SWITCH_UTIL(i2c_module::I2cModule::notification) + +// Addressing +#include + +#define MODULE_ADDRESS_EXISTS_005 EXISTENCE_MARKER_UTIL +#define MODULE_ADDRESS_SWITCH_005 ADDRESS_SWITCH_UTIL(i2c_module::I2cModule::address) + +// All +#include +#include +#include + +namespace Zscript { + +namespace i2c_module { + +template +class I2cModule : public ZscriptModule { + static bool isAddressing; + static bool giveNotifs; + + static void smBusAlertReceived() { + if (giveNotifs) { + notifSrc.set(NULL, 0x50, isAddressing); + } + } + +public: + static GenericCore::ZscriptNotificationSource notifSrc; + + static void setup() { + pinMode(ZP::i2cAlertInPin, INPUT_PULLUP); + attachInterrupt(digitalPinToInterrupt(ZP::i2cAlertInPin), &smBusAlertReceived, FALLING); + pinMode(ZP::i2cAlertInPin, INPUT_PULLUP); + + Wire.begin(); + } + + static void poll() { + if (digitalRead(ZP::i2cAlertInPin) == LOW) { + smBusAlertReceived(); + } + } + + static void execute(ZscriptCommandContext ctx, uint8_t bottomBits) { + switch (bottomBits) { + case ZscriptI2cCapabilitiesCommand::CODE: + ZscriptI2cCapabilitiesCommand::execute(ctx, MODULE_CAPABILITIES(005)); + break; + case ZscriptI2cSetupCommand::CODE: + ZscriptI2cSetupCommand::execute(ctx, &isAddressing, &giveNotifs); + break; + case GeneralI2cAction::SEND_CODE: + GeneralI2cAction::executeSendReceive(ctx, GeneralI2cAction::ActionType::SEND); + break; + case GeneralI2cAction::RECEIVE_CODE: + GeneralI2cAction::executeSendReceive(ctx, GeneralI2cAction::ActionType::RECEIVE); + break; + case GeneralI2cAction::SEND_RECEIVE_CODE: + GeneralI2cAction::executeSendReceive(ctx, GeneralI2cAction::ActionType::SEND_RECEIVE); + break; + default: + ctx.status(ResponseStatus::COMMAND_NOT_FOUND); + break; + } + } + + static void address(ZscriptAddressingContext ctx) { + if (!isAddressing) { + ctx.status(ResponseStatus::ADDRESS_NOT_FOUND); + return; + } + GeneralI2cAction::executeAddressing(ctx); + } + + static void notification(ZscriptNotificationContext ctx, bool moveAlong) { + ZscriptI2cNotification::notification(ctx, moveAlong, isAddressing); + } +}; + +template +bool I2cModule::isAddressing = false; + +template +bool I2cModule::giveNotifs = false; + +template +GenericCore::ZscriptNotificationSource I2cModule::notifSrc; + +} + +} + diff --git a/receivers/native/arduino/src/main/c++/arduino/i2c-module/channels/I2cChannel.hpp b/receivers/native/arduino/src/main/c++/arduino/i2c-module/channels/I2cChannel.hpp index b9737fe09..15505aa7f 100644 --- a/receivers/native/arduino/src/main/c++/arduino/i2c-module/channels/I2cChannel.hpp +++ b/receivers/native/arduino/src/main/c++/arduino/i2c-module/channels/I2cChannel.hpp @@ -5,14 +5,12 @@ * SPDX-License-Identifier: MIT */ -#ifndef SRC_MAIN_CPP_ARDUINO_I2C_MODULE_CHANNELS_ZSCRIPTI2CCHANNEL_HPP_ -#define SRC_MAIN_CPP_ARDUINO_I2C_MODULE_CHANNELS_ZSCRIPTI2CCHANNEL_HPP_ +#if defined(SRC_ZSCRIPT_BASE_I2C_CHANNEL) +#error This file should not be included more than once +#endif +#define SRC_ZSCRIPT_BASE_I2C_CHANNEL - -#include -#include - -#include "../I2cManager.hpp" +#include namespace Zscript { @@ -252,5 +250,3 @@ bool I2cChannel::usingTmp = false; } } - -#endif /* SRC_MAIN_CPP_ARDUINO_I2C_MODULE_CHANNELS_ZSCRIPTI2CCHANNEL_HPP_ */ diff --git a/receivers/native/arduino/src/main/c++/arduino/i2c-module/channels/I2cSmbusExtras.hpp b/receivers/native/arduino/src/main/c++/arduino/i2c-module/channels/I2cSmbusExtras.hpp new file mode 100644 index 000000000..15e7b40db --- /dev/null +++ b/receivers/native/arduino/src/main/c++/arduino/i2c-module/channels/I2cSmbusExtras.hpp @@ -0,0 +1,52 @@ +/* + * Zscript Library - Command System for Microcontrollers) + * Copyright (c) 2022 Zscript team (Susan Witts, Alicia Witts) + * + * SPDX-License-Identifier: MIT + */ + +#if defined(SRC_ZSCRIPT_BASE_I2C_SMBUS_EXTRAS) +#error This file should not be included more than once +#endif +#define SRC_ZSCRIPT_BASE_I2C_SMBUS_EXTRAS + + +#ifndef I2C_ADDRESS_AND_GENERAL_CALL + #if defined(__AVR__) + #define I2C_ADDRESS_AND_GENERAL_CALL(addr) do { TWAR = (addr<<1) | 1; } while(0) + #elif defined(ARDUINO_ARCH_NRF52840) + #define I2C_ADDRESS_AND_GENERAL_CALL(addr) do { NRF_TWIS0->ADDRESS[0] = addr; NRF_TWIS0->ADDRESS[1] = 0; NRF_TWIS0->CONFIG = 0x3; } while(0) + #else + #error "Unknown board, cannot implement I2C address set outside of wire library, so cannot use I2C Channel" + #endif +#endif + +#ifndef I2C_BEGIN_SMBUS_ALERT + #if defined(__AVR__) + #define I2C_BEGIN_SMBUS_ALERT() do { TWAR = (0xC<<1) | 1; } while(0) + #elif defined(ARDUINO_ARCH_NRF52840) + #define I2C_BEGIN_SMBUS_ALERT(addr) do { NRF_TWIS0->ADDRESS[1] = 0xC; } while(0) + #else + #error "Unknown board, cannot implement I2C address set outside of wire library, so cannot use I2C Channel" + #endif +#endif + +#ifndef I2C_END_SMBUS_ALERT + #if defined(__AVR__) + #define I2C_END_SMBUS_ALERT(addr) do { TWAR = (addr<<1) | 1; } while(0) + #elif defined(ARDUINO_ARCH_NRF52840) + #define I2C_END_SMBUS_ALERT(addr) do { NRF_TWIS0->ADDRESS[1] = 0x0; } while(0) + #else + #error "Unknown board, cannot implement I2C address set outside of wire library, so cannot use I2C Channel" + #endif +#endif + +#ifndef I2C_WAS_SMBUS_ALERT_READ + #if defined(__AVR__) + #define I2C_WAS_SMBUS_ALERT_READ() true + #elif defined(ARDUINO_ARCH_NRF52840) + #define I2C_WAS_SMBUS_ALERT_READ() (NRF_TWIS0->MATCH == 1) + #else + #error "Unknown board, cannot implement I2C address set outside of wire library, so cannot use I2C Channel" + #endif +#endif diff --git a/receivers/native/arduino/src/main/c++/arduino/i2c-module/commands/GeneralI2cAction.hpp b/receivers/native/arduino/src/main/c++/arduino/i2c-module/commands/GeneralI2cAction.hpp index 10ec91a40..31582cec5 100644 --- a/receivers/native/arduino/src/main/c++/arduino/i2c-module/commands/GeneralI2cAction.hpp +++ b/receivers/native/arduino/src/main/c++/arduino/i2c-module/commands/GeneralI2cAction.hpp @@ -5,12 +5,10 @@ * SPDX-License-Identifier: MIT */ -#ifndef SRC_MAIN_CPP_ARDUINO_I2C_MODULE_COMMANDS_GENERALI2CACTION_HPP_ -#define SRC_MAIN_CPP_ARDUINO_I2C_MODULE_COMMANDS_GENERALI2CACTION_HPP_ - -#include -#include -#include +#if defined(SRC_ZSCRIPT_BASE_I2C_GENERAL_ACTION) +#error This file should not be included more than once +#endif +#define SRC_ZSCRIPT_BASE_I2C_GENERAL_ACTION #define COMMAND_EXISTS_0052 EXISTENCE_MARKER_UTIL #define COMMAND_EXISTS_0053 EXISTENCE_MARKER_UTIL @@ -269,5 +267,3 @@ class GeneralI2cAction: I2cSendReceive_CommandDefs { } } - -#endif /* SRC_MAIN_CPP_ARDUINO_I2C_MODULE_COMMANDS_GENERALI2CACTION_HPP_ */ diff --git a/receivers/native/arduino/src/main/c++/arduino/i2c-module/commands/I2cCapabilitiesCommand.hpp b/receivers/native/arduino/src/main/c++/arduino/i2c-module/commands/I2cCapabilitiesCommand.hpp index d0b4027ab..64618d316 100644 --- a/receivers/native/arduino/src/main/c++/arduino/i2c-module/commands/I2cCapabilitiesCommand.hpp +++ b/receivers/native/arduino/src/main/c++/arduino/i2c-module/commands/I2cCapabilitiesCommand.hpp @@ -5,12 +5,11 @@ * SPDX-License-Identifier: MIT */ -#ifndef SRC_MAIN_CPP_ARDUINO_I2C_MODULE_COMMANDS_ZSCRIPTI2CCAPABILITIESCOMMAND_HPP_ -#define SRC_MAIN_CPP_ARDUINO_I2C_MODULE_COMMANDS_ZSCRIPTI2CCAPABILITIESCOMMAND_HPP_ +#if defined(SRC_ZSCRIPT_BASE_I2C_CAPABILITIES_COMMAND) +#error This file should not be included more than once +#endif +#define SRC_ZSCRIPT_BASE_I2C_CAPABILITIES_COMMAND -#include -#include -#include #define COMMAND_EXISTS_0050 EXISTENCE_MARKER_UTIL @@ -26,11 +25,11 @@ class ZscriptI2cCapabilitiesCommand : public Capabilities_CommandDefs { out.writeField(RespCommandsSet__C, commandsSet); out.writeField(RespInterfaceCount__I, 1); out.writeField(RespFrequenciesSupported__F, 3); -#ifdef ZSCRIPT_HAVE_I2C_MODULE +#ifdef ZSCRIPT_HAVE_I2C_GENERAL out.writeField(RespBitsetCapabilities__B, RespBitsetCapabilities_Values::lowSpeedSupported_field | RespBitsetCapabilities_Values::smBusAddressResolution_field); #else - out.writeField(RespBitsetCapabilities__B, RespBitsetCapabilities__LowSpeedSupported); + out.writeField(RespBitsetCapabilities__B, RespBitsetCapabilities_Values::lowSpeedSupported_field); #endif #ifdef ZSCRIPT_I2C_SUPPORT_NOTIFICATIONS out.writeField(RespNotificationsSupported__N, 0); @@ -44,5 +43,3 @@ class ZscriptI2cCapabilitiesCommand : public Capabilities_CommandDefs { } } - -#endif /* SRC_MAIN_CPP_ARDUINO_I2C_MODULE_COMMANDS_ZSCRIPTI2CCAPABILITIESCOMMAND_HPP_ */ diff --git a/receivers/native/arduino/src/main/c++/arduino/i2c-module/commands/I2cChannelInfo.hpp b/receivers/native/arduino/src/main/c++/arduino/i2c-module/commands/I2cChannelInfo.hpp index 12cfccac4..b7c66b55e 100644 --- a/receivers/native/arduino/src/main/c++/arduino/i2c-module/commands/I2cChannelInfo.hpp +++ b/receivers/native/arduino/src/main/c++/arduino/i2c-module/commands/I2cChannelInfo.hpp @@ -5,12 +5,10 @@ * SPDX-License-Identifier: MIT */ -#ifndef SRC_MAIN_CPP_ARDUINO_I2C_MODULE_COMMANDS_ZSCRIPTI2CCHANNELINFOCOMMAND_HPP_ -#define SRC_MAIN_CPP_ARDUINO_I2C_MODULE_COMMANDS_ZSCRIPTI2CCHANNELINFOCOMMAND_HPP_ - -#include -#include -#include +#if defined(SRC_ZSCRIPT_BASE_I2C_CHANNEL_INFO_COMMAND) +#error This file should not be included more than once +#endif +#define SRC_ZSCRIPT_BASE_I2C_CHANNEL_INFO_COMMAND #define COMMAND_EXISTS_005c EXISTENCE_MARKER_UTIL @@ -28,7 +26,7 @@ template class I2cChannel; template -class ZscriptI2cChannelInfoCommand: public ChannelInfo_CommandDefs { +class ZscriptI2cChannelInfoCommand : public ChannelInfo_CommandDefs { public: static void execute(ZscriptCommandContext ctx) { uint16_t channelIndex; @@ -51,5 +49,3 @@ class ZscriptI2cChannelInfoCommand: public ChannelInfo_CommandDefs { } } - -#endif //SRC_MAIN_CPP_ARDUINO_I2C_MODULE_COMMANDS_ZSCRIPTI2CCHANNELINFOCOMMAND_HPP_ diff --git a/receivers/native/arduino/src/main/c++/arduino/i2c-module/commands/I2cChannelSetup.hpp b/receivers/native/arduino/src/main/c++/arduino/i2c-module/commands/I2cChannelSetup.hpp index 3ac5718d3..10e36bf30 100644 --- a/receivers/native/arduino/src/main/c++/arduino/i2c-module/commands/I2cChannelSetup.hpp +++ b/receivers/native/arduino/src/main/c++/arduino/i2c-module/commands/I2cChannelSetup.hpp @@ -5,12 +5,10 @@ * SPDX-License-Identifier: MIT */ -#ifndef SRC_MAIN_CPP_ARDUINO_I2C_MODULE_COMMANDS_ZSCRIPTI2CCHANNELSETUPCOMMAND_HPP_ -#define SRC_MAIN_CPP_ARDUINO_I2C_MODULE_COMMANDS_ZSCRIPTI2CCHANNELSETUPCOMMAND_HPP_ - -#include -#include -#include +#if defined(SRC_ZSCRIPT_BASE_I2C_CHANNEL_SETUP_COMMAND) +#error This file should not be included more than once +#endif +#define SRC_ZSCRIPT_BASE_I2C_CHANNEL_SETUP_COMMAND #define COMMAND_EXISTS_005d EXISTENCE_MARKER_UTIL @@ -25,7 +23,7 @@ template class I2cModule; template -class ZscriptI2cChannelSetupCommand: public ChannelSetup_CommandDefs { +class ZscriptI2cChannelSetupCommand : public ChannelSetup_CommandDefs { public: static void execute(ZscriptCommandContext ctx) { uint16_t channelIndex; @@ -52,5 +50,3 @@ class ZscriptI2cChannelSetupCommand: public ChannelSetup_CommandDefs { } } - -#endif //SRC_MAIN_CPP_ARDUINO_I2C_MODULE_COMMANDS_ZSCRIPTI2CCHANNELSETUPCOMMAND_HPP_ diff --git a/receivers/native/arduino/src/main/c++/arduino/i2c-module/commands/I2cSetupCommand.hpp b/receivers/native/arduino/src/main/c++/arduino/i2c-module/commands/I2cSetupCommand.hpp index 450a389c1..c6735fb9d 100644 --- a/receivers/native/arduino/src/main/c++/arduino/i2c-module/commands/I2cSetupCommand.hpp +++ b/receivers/native/arduino/src/main/c++/arduino/i2c-module/commands/I2cSetupCommand.hpp @@ -5,12 +5,10 @@ * SPDX-License-Identifier: MIT */ -#ifndef SRC_MAIN_CPP_ARDUINO_I2C_MODULE_COMMANDS_ZSCRIPTI2CSETUPCOMMAND_HPP_ -#define SRC_MAIN_CPP_ARDUINO_I2C_MODULE_COMMANDS_ZSCRIPTI2CSETUPCOMMAND_HPP_ - -#include -#include -#include +#if defined(SRC_ZSCRIPT_BASE_I2C_SETUP_COMMAND) +#error This file should not be included more than once +#endif +#define SRC_ZSCRIPT_BASE_I2C_SETUP_COMMAND #define COMMAND_EXISTS_0051 EXISTENCE_MARKER_UTIL @@ -22,7 +20,7 @@ template class ZscriptI2cSetupCommand: public I2cSetup_CommandDefs { public: static void execute(ZscriptCommandContext ctx -#ifdef ZSCRIPT_I2C_SUPPORT_NOTIFICATIONS +#ifdef SRC_ZSCRIPT_BASE_I2C_NOTIFICATION , bool *addressing, bool *notifications #endif ) { @@ -74,5 +72,3 @@ class ZscriptI2cSetupCommand: public I2cSetup_CommandDefs { } } - -#endif /* SRC_MAIN_CPP_ARDUINO_I2C_MODULE_COMMANDS_ZSCRIPTI2CSETUPCOMMAND_HPP_ */ diff --git a/receivers/native/arduino/src/main/c++/arduino/i2c-module/notifications/I2cNotification.hpp b/receivers/native/arduino/src/main/c++/arduino/i2c-module/notifications/I2cNotification.hpp index 49aa95b0f..dbae5a1be 100644 --- a/receivers/native/arduino/src/main/c++/arduino/i2c-module/notifications/I2cNotification.hpp +++ b/receivers/native/arduino/src/main/c++/arduino/i2c-module/notifications/I2cNotification.hpp @@ -4,21 +4,12 @@ * * SPDX-License-Identifier: MIT */ - -#ifndef SRC_MAIN_CPP_ARDUINO_I2C_MODULE_NOTIFICATIONS_ZSCRIPTI2CNOTIFICATION_HPP_ -#define SRC_MAIN_CPP_ARDUINO_I2C_MODULE_NOTIFICATIONS_ZSCRIPTI2CNOTIFICATION_HPP_ - -#if !defined(ZSCRIPT_I2C_SUPPORT_NOTIFICATIONS) - #error ZSCRIPT_I2C_SUPPORT_NOTIFICATIONS should be enabled to ensure all notification components are included -#endif - -#if !defined(ZSCRIPT_SUPPORT_NOTIFICATIONS) - #error ZSCRIPT_I2C_SUPPORT_NOTIFICATIONS requires ZSCRIPT_SUPPORT_NOTIFICATIONS to be enabled +#if defined(SRC_ZSCRIPT_BASE_I2C_NOTIFICATION) +#error This file should not be included more than once #endif +#define SRC_ZSCRIPT_BASE_I2C_NOTIFICATION -#include #include -#include namespace Zscript { @@ -91,4 +82,3 @@ class ZscriptI2cNotification { } } -#endif //SRC_MAIN_CPP_ARDUINO_I2C_MODULE_NOTIFICATIONS_ZSCRIPTI2CNOTIFICATION_HPP_ \ No newline at end of file diff --git a/receivers/native/arduino/src/main/c++/examples/I2cChannelDemo/ZscriptParameters.hpp b/receivers/native/arduino/src/main/c++/examples/I2cChannelDemo/ZscriptParameters.hpp index 9bc9d01fd..3e998d362 100644 --- a/receivers/native/arduino/src/main/c++/examples/I2cChannelDemo/ZscriptParameters.hpp +++ b/receivers/native/arduino/src/main/c++/examples/I2cChannelDemo/ZscriptParameters.hpp @@ -8,8 +8,8 @@ #ifndef SRC_MAIN_CPP_FIRSTARDUINOTEST_ZSCRIPTPARAMETERS_HPP_ #define SRC_MAIN_CPP_FIRSTARDUINOTEST_ZSCRIPTPARAMETERS_HPP_ -#define ZSCRIPT_IDENTIFY_USER_FIRMWARE_STRING "Zscript Arduino Example" -#define ZSCRIPT_IDENTIFY_USER_FIRMWARE_VERSION 0x0001 +#define ZSCRIPT_IDENTIFY_USER_FIRMWARE_STRING "Zscript Arduino Example" +#define ZSCRIPT_IDENTIFY_USER_FIRMWARE_VERSION 0x0001 #define ZSCRIPT_IDENTIFY_USER_HARDWARE_STRING "Test setup" #define ZSCRIPT_IDENTIFY_USER_HARDWARE_VERSION 0x0000 @@ -23,17 +23,13 @@ // Please note that ZscriptFullInclude will set any #defines necessary to other set #defines - eg ZSCRIPT_USE_DEBUG_ADDRESSING_SYSTEM enables ZSCRIPT_SUPPORT_DEBUG //#define ZSCRIPT_SUPPORT_SCRIPT_SPACE -#define ZSCRIPT_SUPPORT_NOTIFICATIONS +//#define ZSCRIPT_SUPPORT_NOTIFICATIONS //#define ZSCRIPT_SUPPORT_ADDRESSING // -//#define ZSCRIPT_HAVE_PIN_MODULE -//#define ZSCRIPT_PIN_SUPPORT_NOTIFICATIONS +#define ZSCRIPT_HAVE_PIN_MODULE +#define ZSCRIPT_PIN_SUPPORT_NOTIFICATIONS //#define ZSCRIPT_PIN_SUPPORT_ANALOG_NOTIFICATIONS // -#define ZSCRIPT_HAVE_I2C_MODULE -#define ZSCRIPT_I2C_SUPPORT_NOTIFICATIONS -#define ZSCRIPT_HAVE_I2C_CHANNEL - #define ZSCRIPT_HAVE_UART_MODULE #define ZSCRIPT_HAVE_UART_CHANNEL diff --git a/receivers/native/arduino/src/main/c++/examples/UartChannelDemo/ZscriptParameters.hpp b/receivers/native/arduino/src/main/c++/examples/UartChannelDemo/ZscriptParameters.hpp index f7e4de122..a36526f91 100644 --- a/receivers/native/arduino/src/main/c++/examples/UartChannelDemo/ZscriptParameters.hpp +++ b/receivers/native/arduino/src/main/c++/examples/UartChannelDemo/ZscriptParameters.hpp @@ -8,8 +8,8 @@ #ifndef SRC_MAIN_CPP_FIRSTARDUINOTEST_ZSCRIPTPARAMETERS_HPP_ #define SRC_MAIN_CPP_FIRSTARDUINOTEST_ZSCRIPTPARAMETERS_HPP_ -#define ZSCRIPT_IDENTIFY_USER_FIRMWARE_STRING "Zscript Arduino Example" -#define ZSCRIPT_IDENTIFY_USER_FIRMWARE_VERSION 0x0001 +#define ZSCRIPT_IDENTIFY_USER_FIRMWARE_STRING "Zscript Arduino Example" +#define ZSCRIPT_IDENTIFY_USER_FIRMWARE_VERSION 0x0001 #define ZSCRIPT_IDENTIFY_USER_HARDWARE_STRING "Test setup" #define ZSCRIPT_IDENTIFY_USER_HARDWARE_VERSION 0x0000 @@ -23,16 +23,17 @@ // Please note that ZscriptFullInclude will set any #defines necessary to other set #defines - eg ZSCRIPT_USE_DEBUG_ADDRESSING_SYSTEM enables ZSCRIPT_SUPPORT_DEBUG //#define ZSCRIPT_SUPPORT_SCRIPT_SPACE -//#define ZSCRIPT_SUPPORT_NOTIFICATIONS -//#define ZSCRIPT_SUPPORT_ADDRESSING +#define ZSCRIPT_SUPPORT_NOTIFICATIONS +#define ZSCRIPT_SUPPORT_ADDRESSING // #define ZSCRIPT_HAVE_PIN_MODULE #define ZSCRIPT_PIN_SUPPORT_NOTIFICATIONS //#define ZSCRIPT_PIN_SUPPORT_ANALOG_NOTIFICATIONS // -#define ZSCRIPT_HAVE_I2C_MODULE -//#define ZSCRIPT_I2C_SUPPORT_NOTIFICATIONS -#define ZSCRIPT_HAVE_I2C_CHANNEL +// fixme: TO BE REMOVED +//#define ZSCRIPT_HAVE_I2C_GENERAL +////#define ZSCRIPT_I2C_SUPPORT_NOTIFICATIONS +//#define ZSCRIPT_HAVE_I2C_CHANNEL #define ZSCRIPT_HAVE_UART_MODULE #define ZSCRIPT_HAVE_UART_CHANNEL diff --git a/receivers/native/arduino/src/main/resources/library-setup/keywords.txt b/receivers/native/arduino/src/main/resources/library-setup/keywords.txt index bf8d3b526..d67472b82 100644 --- a/receivers/native/arduino/src/main/resources/library-setup/keywords.txt +++ b/receivers/native/arduino/src/main/resources/library-setup/keywords.txt @@ -45,7 +45,7 @@ ZSCRIPT_SUPPORT_DEBUG LITERAL1 ZSCRIPT_HAVE_I2C_CHANNEL LITERAL1 ZSCRIPT_HAVE_UART_CHANNEL LITERAL1 ZSCRIPT_HAVE_PIN_MODULE LITERAL1 -ZSCRIPT_HAVE_I2C_MODULE LITERAL1 +ZSCRIPT_HAVE_I2C_GENERAL LITERAL1 ZSCRIPT_USE_MODULE_ADDRESSING LITERAL1 ZSCRIPT_USE_DEBUG_ADDRESSING_SYSTEM LITERAL1 ZSCRIPT_USE_MODULE_ADDRESSING LITERAL1