diff --git a/firmware-template-h3/Common.mk b/firmware-template-h3/Common.mk new file mode 100755 index 000000000..25f48d3a0 --- /dev/null +++ b/firmware-template-h3/Common.mk @@ -0,0 +1,13 @@ +$(info "Common.mk") +$(info $$DEFINES [${DEFINES}]) + +DEFINES+=-DPHY_GENERIC=255 +DEFINES+=-DPHY_TYPE=PHY_GENERIC +DEFINES+=-DENABLE_TFTP_SERVER +DEFINES+=-DCONFIG_MDNS_DOMAIN_REVERSE +DEFINES+=-DISABLE_INTERNAL_RTC +DEFINES+=-D__FPU_PRESENT=1 -D__GIC_PRESENT=1 +#DEFINES+=-DTCP_TX_QUEUE_SIZE=2 +DEFINES+=-DHTTPD_CONTENT_SIZE=4096 + +$(info $$DEFINES [${DEFINES}]) \ No newline at end of file diff --git a/firmware-template-h3/Rules.mk b/firmware-template-h3/Rules.mk index 16f52f1b4..2b165ca5b 100644 --- a/firmware-template-h3/Rules.mk +++ b/firmware-template-h3/Rules.mk @@ -52,13 +52,7 @@ ifneq ($(findstring _TIME_STAMP_YEAR_,$(DEFINES)), _TIME_STAMP_YEAR_) DEFINES+=-D_TIME_STAMP_YEAR_=$(shell date +"%Y") -D_TIME_STAMP_MONTH_=$(shell date +"%-m") -D_TIME_STAMP_DAY_=$(shell date +"%-d") endif -DEFINES+=-DBARE_METAL -DH3 -DEFINES+=-DPHY_GENERIC=255 -DEFINES+=-DPHY_TYPE=PHY_GENERIC -DEFINES+=-DENABLE_TFTP_SERVER -DEFINES+=-DCONFIG_MDNS_DOMAIN_REVERSE -DEFINES+=-DISABLE_INTERNAL_RTC -DEFINES+=-D__FPU_PRESENT=1 -D__GIC_PRESENT=1 +include ../firmware-template-h3/Common.mk ifneq ($(findstring CONFIG_STORE_USE_SPI,$(DEFINES)), CONFIG_STORE_USE_SPI) DEFINES+=-DCONFIG_STORE_USE_SPI @@ -90,7 +84,7 @@ LIBDEP=$(addprefix ../lib-,$(LIBS)) $(info [${LIBDEP}]) -COPS=-D$(PLATFORM) $(DEFINES) +COPS=-DBARE_METAL -DH3 -D$(PLATFORM) $(DEFINES) COPS+=$(INCDIRS) $(LIBINCDIRS) $(addprefix -I,$(EXTRA_INCLUDES)) COPS+=-mfpu=neon-vfpv4 -mcpu=cortex-a7 -mfloat-abi=hard -mhard-float COPS+=-nostartfiles -ffreestanding -nostdlib -fprefetch-loop-arrays diff --git a/firmware-template-h3/lib/Rules.mk b/firmware-template-h3/lib/Rules.mk index 83b474de0..693748562 100644 --- a/firmware-template-h3/lib/Rules.mk +++ b/firmware-template-h3/lib/Rules.mk @@ -35,12 +35,7 @@ ifneq ($(findstring _TIME_STAMP_YEAR_,$(DEFINES)), _TIME_STAMP_YEAR_) DEFINES+=-D_TIME_STAMP_YEAR_=$(shell date +"%Y") -D_TIME_STAMP_MONTH_=$(shell date +"%-m") -D_TIME_STAMP_DAY_=$(shell date +"%-d") endif -DEFINES+=-DPHY_GENERIC=255 -DEFINES+=-DPHY_TYPE=PHY_GENERIC -DEFINES+=-DENABLE_TFTP_SERVER -DEFINES+=-DCONFIG_MDNS_DOMAIN_REVERSE -DEFINES+=-DISABLE_INTERNAL_RTC -DEFINES+=-D__FPU_PRESENT=1 -D__GIC_PRESENT=1 +include ../firmware-template-h3/Common.mk ifneq ($(findstring CONFIG_STORE_USE_SPI,$(DEFINES)), CONFIG_STORE_USE_SPI) DEFINES+=-DCONFIG_STORE_USE_SPI diff --git a/lib-arm/.settings/language.settings.xml b/lib-arm/.settings/language.settings.xml index 330240762..552b63f18 100644 --- a/lib-arm/.settings/language.settings.xml +++ b/lib-arm/.settings/language.settings.xml @@ -5,7 +5,7 @@ - + @@ -17,7 +17,7 @@ - + diff --git a/lib-artnet/.settings/language.settings.xml b/lib-artnet/.settings/language.settings.xml index db163d342..30e669b07 100644 --- a/lib-artnet/.settings/language.settings.xml +++ b/lib-artnet/.settings/language.settings.xml @@ -5,7 +5,7 @@ - + @@ -17,7 +17,7 @@ - + diff --git a/lib-artnet/Makefile.H3 b/lib-artnet/Makefile.H3 index 886e31480..3582ff3a2 100644 --- a/lib-artnet/Makefile.H3 +++ b/lib-artnet/Makefile.H3 @@ -1,4 +1,4 @@ -#DEFINES=NDEBUG +DEFINES=NDEBUG EXTRA_INCLUDES= diff --git a/lib-artnet/include/artnetcontroller.h b/lib-artnet/include/artnetcontroller.h index 689bc292f..6df7b7a9a 100644 --- a/lib-artnet/include/artnetcontroller.h +++ b/lib-artnet/include/artnetcontroller.h @@ -51,8 +51,6 @@ struct State { }; struct TArtNetController { - uint32_t nIPAddressLocal; - uint32_t nIPAddressBroadcast; uint8_t Oem[2]; }; diff --git a/lib-artnet/src/controller/artnetcontroller.cpp b/lib-artnet/src/controller/artnetcontroller.cpp index 9c8f56bd8..ec2ea1a79 100644 --- a/lib-artnet/src/controller/artnetcontroller.cpp +++ b/lib-artnet/src/controller/artnetcontroller.cpp @@ -5,7 +5,7 @@ /** * Art-Net Designed by and Copyright Artistic Licence Holdings Ltd. */ -/* Copyright (C) 2017-2024 by Arjan van Vught mailto:info@orangepi-dmx.nl +/* Copyright (C) 2017-2024 by Arjan van Vught mailto:info@gd32-dmx.org * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -230,14 +230,11 @@ void ArtNetController::SetLongName(const char *pLongName) { void ArtNetController::Start() { DEBUG_ENTRY - m_ArtNetController.nIPAddressLocal = Network::Get()->GetIp(); - m_ArtNetController.nIPAddressBroadcast = Network::Get()->GetBroadcastIp(); - assert(m_nHandle == -1); m_nHandle = Network::Get()->Begin(artnet::UDP_PORT); assert(m_nHandle != -1); - Network::Get()->SendTo(m_nHandle, &m_ArtNetPoll, sizeof(struct ArtPoll), m_ArtNetController.nIPAddressBroadcast, artnet::UDP_PORT); + Network::Get()->SendTo(m_nHandle, &m_ArtNetPoll, sizeof(struct ArtPoll), Network::Get()->GetBroadcastIp(), artnet::UDP_PORT); m_State.status = artnet::Status::ON; @@ -315,7 +312,7 @@ void ArtNetController::HandleDmxOut(uint16_t nUniverse, const uint8_t *pDmxData, } if (!m_bUnicast || (nCount > 40) || !m_bForceBroadcast) { - Network::Get()->SendTo(m_nHandle, m_pArtDmx, sizeof(struct ArtDmx), m_ArtNetController.nIPAddressBroadcast, artnet::UDP_PORT); + Network::Get()->SendTo(m_nHandle, m_pArtDmx, sizeof(struct ArtDmx), Network::Get()->GetBroadcastIp(), artnet::UDP_PORT); m_bDmxHandled = true; } @@ -326,7 +323,7 @@ void ArtNetController::HandleDmxOut(uint16_t nUniverse, const uint8_t *pDmxData, void ArtNetController::HandleSync() { if (m_bSynchronization && m_bDmxHandled) { m_bDmxHandled = false; - Network::Get()->SendTo(m_nHandle, m_pArtSync, sizeof(struct ArtSync), m_ArtNetController.nIPAddressBroadcast, artnet::UDP_PORT); + Network::Get()->SendTo(m_nHandle, m_pArtSync, sizeof(struct ArtSync), Network::Get()->GetBroadcastIp(), artnet::UDP_PORT); } } @@ -375,7 +372,7 @@ void ArtNetController::HandleBlackout() { m_pArtDmx->Sequence = 1; } - Network::Get()->SendTo(m_nHandle, m_pArtDmx, sizeof(struct ArtDmx), m_ArtNetController.nIPAddressBroadcast, artnet::UDP_PORT); + Network::Get()->SendTo(m_nHandle, m_pArtDmx, sizeof(struct ArtDmx), Network::Get()->GetBroadcastIp(), artnet::UDP_PORT); } } @@ -401,7 +398,7 @@ void ArtNetController::ProcessPoll() { const auto nCurrentMillis = Hardware::Get()->Millis(); if (__builtin_expect((nCurrentMillis - m_nLastPollMillis > POLL_INTERVAL_MILLIS), 0)) { - Network::Get()->SendTo(m_nHandle, &m_ArtNetPoll, sizeof(struct ArtPoll), m_ArtNetController.nIPAddressBroadcast, artnet::UDP_PORT); + Network::Get()->SendTo(m_nHandle, &m_ArtNetPoll, sizeof(struct ArtPoll), Network::Get()->GetBroadcastIp(), artnet::UDP_PORT); m_nLastPollMillis= nCurrentMillis; #ifndef NDEBUG diff --git a/lib-artnet/src/controller/artnetpolltable.cpp b/lib-artnet/src/controller/artnetpolltable.cpp index 8b0251a19..2bcb665be 100644 --- a/lib-artnet/src/controller/artnetpolltable.cpp +++ b/lib-artnet/src/controller/artnetpolltable.cpp @@ -72,8 +72,8 @@ ArtNetPollTable::ArtNetPollTable() { m_PollTableClean.nUniverseIndex = 0; m_PollTableClean.bOffLine = true; - DEBUG_PRINTF("NodeEntry[%d] = %u bytes [%u Kb]", artnet::POLL_TABLE_SIZE_ENRIES, static_cast(sizeof(artnet::NodeEntry[artnet::POLL_TABLE_SIZE_ENRIES])), static_cast(sizeof(artnet::NodeEntry[artnet::POLL_TABLE_SIZE_ENRIES])) / 1024U); - DEBUG_PRINTF("PollTableUniverses[%d] = %u bytes [%u Kb]", artnet::POLL_TABLE_SIZE_UNIVERSES, static_cast(sizeof(artnet::PollTableUniverses[artnet::POLL_TABLE_SIZE_UNIVERSES])), static_cast(sizeof(artnet::PollTableUniverses[artnet::POLL_TABLE_SIZE_UNIVERSES])) / 1024U); + DEBUG_PRINTF("NodeEntry[%d] = %u bytes [%u Kb]", artnet::POLL_TABLE_SIZE_ENRIES, (sizeof(artnet::NodeEntry[artnet::POLL_TABLE_SIZE_ENRIES])), (sizeof(artnet::NodeEntry[artnet::POLL_TABLE_SIZE_ENRIES])) / 1024U); + DEBUG_PRINTF("PollTableUniverses[%d] = %u bytes [%u Kb]", artnet::POLL_TABLE_SIZE_UNIVERSES, (sizeof(artnet::PollTableUniverses[artnet::POLL_TABLE_SIZE_UNIVERSES])), (sizeof(artnet::PollTableUniverses[artnet::POLL_TABLE_SIZE_UNIVERSES])) / 1024U); DEBUG_EXIT } diff --git a/lib-bcm2835/.settings/language.settings.xml b/lib-bcm2835/.settings/language.settings.xml index b2b5c4ba9..9ac84d157 100644 --- a/lib-bcm2835/.settings/language.settings.xml +++ b/lib-bcm2835/.settings/language.settings.xml @@ -5,7 +5,7 @@ - + diff --git a/lib-configstore/.settings/language.settings.xml b/lib-configstore/.settings/language.settings.xml index 56b8506bb..ec4f6fc73 100755 --- a/lib-configstore/.settings/language.settings.xml +++ b/lib-configstore/.settings/language.settings.xml @@ -5,7 +5,7 @@ - + diff --git a/lib-ddp/.settings/language.settings.xml b/lib-ddp/.settings/language.settings.xml index 99075d0fc..6eba6edbe 100755 --- a/lib-ddp/.settings/language.settings.xml +++ b/lib-ddp/.settings/language.settings.xml @@ -5,7 +5,7 @@ - + @@ -17,7 +17,7 @@ - + diff --git a/lib-device/.settings/language.settings.xml b/lib-device/.settings/language.settings.xml index 9436a33d5..c5fbb2573 100644 --- a/lib-device/.settings/language.settings.xml +++ b/lib-device/.settings/language.settings.xml @@ -5,7 +5,7 @@ - + @@ -17,7 +17,7 @@ - + diff --git a/lib-display/.settings/language.settings.xml b/lib-display/.settings/language.settings.xml index e1347450b..b30fd3a92 100755 --- a/lib-display/.settings/language.settings.xml +++ b/lib-display/.settings/language.settings.xml @@ -5,7 +5,7 @@ - + @@ -17,7 +17,7 @@ - + @@ -29,7 +29,7 @@ - + diff --git a/lib-displayudf/.settings/language.settings.xml b/lib-displayudf/.settings/language.settings.xml index 40099f716..8dca8fd90 100644 --- a/lib-displayudf/.settings/language.settings.xml +++ b/lib-displayudf/.settings/language.settings.xml @@ -5,7 +5,7 @@ - + diff --git a/lib-dmx/.settings/language.settings.xml b/lib-dmx/.settings/language.settings.xml index 017a2c499..360039aff 100644 --- a/lib-dmx/.settings/language.settings.xml +++ b/lib-dmx/.settings/language.settings.xml @@ -5,7 +5,7 @@ - + @@ -17,7 +17,7 @@ - + diff --git a/lib-dmxserial/.settings/language.settings.xml b/lib-dmxserial/.settings/language.settings.xml index 11b40c905..34dee09c5 100644 --- a/lib-dmxserial/.settings/language.settings.xml +++ b/lib-dmxserial/.settings/language.settings.xml @@ -5,7 +5,7 @@ - + @@ -17,7 +17,7 @@ - + diff --git a/lib-e131/.settings/language.settings.xml b/lib-e131/.settings/language.settings.xml index 04b47eed8..5f41054bf 100644 --- a/lib-e131/.settings/language.settings.xml +++ b/lib-e131/.settings/language.settings.xml @@ -5,7 +5,7 @@ - + @@ -17,7 +17,7 @@ - + @@ -29,7 +29,7 @@ - + diff --git a/lib-flash/.settings/language.settings.xml b/lib-flash/.settings/language.settings.xml index f789c496c..b5de257f2 100755 --- a/lib-flash/.settings/language.settings.xml +++ b/lib-flash/.settings/language.settings.xml @@ -5,7 +5,7 @@ - + diff --git a/lib-flash/src/spi/spi_flash_internal.h b/lib-flash/src/spi/spi_flash_internal.h index 019fff1a1..0acd9b93a 100644 --- a/lib-flash/src/spi/spi_flash_internal.h +++ b/lib-flash/src/spi/spi_flash_internal.h @@ -74,16 +74,17 @@ struct spi_flash { #define SPI_XFER_SPEED_HZ 6000000 ///< 6MHz -extern int spi_init(); -extern int spi_xfer(uint32_t bitlen, const uint8_t *dout, uint8_t *din, uint32_t flags); +int spi_init(); +int spi_xfer(uint32_t bitlen, const uint8_t *dout, uint8_t *din, uint32_t flags); -//#define CONFIG_SPI_FLASH_MACRONIX -//int spi_flash_probe_macronix(struct spi_flash *flash, uint8_t *idcode); +#if defined (H3) +# define CONFIG_SPI_FLASH_MACRONIX + int spi_flash_probe_macronix(struct spi_flash *flash, uint8_t *idcode); +# define CONFIG_SPI_FLASH_GIGADEVICE + int spi_flash_probe_gigadevice(struct spi_flash *spi, uint8_t *idcode); +#endif #define CONFIG_SPI_FLASH_WINBOND extern int spi_flash_probe_winbond(struct spi_flash *spi, uint8_t *idcode); -//#define CONFIG_SPI_FLASH_GIGADEVICE -//extern int spi_flash_probe_gigadevice(struct spi_flash *spi, uint8_t *idcode); - #endif /* SPI_FLASH_INTERNAL_H_ */ diff --git a/lib-flashcode/.settings/language.settings.xml b/lib-flashcode/.settings/language.settings.xml index 9eda85020..1315b9bfd 100755 --- a/lib-flashcode/.settings/language.settings.xml +++ b/lib-flashcode/.settings/language.settings.xml @@ -5,7 +5,7 @@ - + diff --git a/lib-flashcodeinstall/.settings/language.settings.xml b/lib-flashcodeinstall/.settings/language.settings.xml index 9e1a8f479..9c0161f9a 100755 --- a/lib-flashcodeinstall/.settings/language.settings.xml +++ b/lib-flashcodeinstall/.settings/language.settings.xml @@ -5,7 +5,7 @@ - + diff --git a/lib-gps/.settings/language.settings.xml b/lib-gps/.settings/language.settings.xml index f3e68b7e6..b0aa4e913 100644 --- a/lib-gps/.settings/language.settings.xml +++ b/lib-gps/.settings/language.settings.xml @@ -5,7 +5,7 @@ - + diff --git a/lib-h3/.settings/language.settings.xml b/lib-h3/.settings/language.settings.xml index 561f96630..5daf7d09d 100644 --- a/lib-h3/.settings/language.settings.xml +++ b/lib-h3/.settings/language.settings.xml @@ -5,7 +5,7 @@ - + diff --git a/lib-hal/.settings/language.settings.xml b/lib-hal/.settings/language.settings.xml index 4c842bb94..5cc8b04c4 100644 --- a/lib-hal/.settings/language.settings.xml +++ b/lib-hal/.settings/language.settings.xml @@ -5,7 +5,7 @@ - + @@ -17,7 +17,7 @@ - + diff --git a/lib-hal/console/i2c/console.cpp b/lib-hal/console/i2c/console.cpp index 37be38bfd..d7fd9b41c 100644 --- a/lib-hal/console/i2c/console.cpp +++ b/lib-hal/console/i2c/console.cpp @@ -104,7 +104,7 @@ static void setup() { FUNC_PREFIX(i2c_set_baudrate(400000)); } -static void write_register(uint8_t nRegister, uint8_t nValue) { +static void write_register(const uint8_t nRegister, const uint8_t nValue) { char buffer[2]; buffer[0] = static_cast(nRegister); @@ -187,13 +187,13 @@ void __attribute__((cold)) console_init() { write_register(SC16IS7X0_MCR, MCR); uint8_t EFR = read_register(SC16IS7X0_EFR); - write_register(SC16IS7X0_EFR, (uint8_t) (EFR | EFR_ENABLE_ENHANCED_FUNCTIONS)); + write_register(SC16IS7X0_EFR, (EFR | EFR_ENABLE_ENHANCED_FUNCTIONS)); - write_register(SC16IS7X0_TLR, (uint8_t) (0x10)); + write_register(SC16IS7X0_TLR, (0x10)); write_register(SC16IS7X0_EFR, EFR); - write_register(SC16IS7X0_FCR, (uint8_t) (FCR_TX_FIFO_RST)); + write_register(SC16IS7X0_FCR, (FCR_TX_FIFO_RST)); write_register(SC16IS7X0_FCR, FCR_ENABLE_FIFO); } diff --git a/lib-hal/include/hwclock.h b/lib-hal/include/hwclock.h index 331d293ae..01b2f5cd6 100644 --- a/lib-hal/include/hwclock.h +++ b/lib-hal/include/hwclock.h @@ -3,7 +3,7 @@ * @file hwclock.h * */ -/* Copyright (C) 2020-2023 by Arjan van Vught mailto:info@orangepi-dmx.nl +/* Copyright (C) 2020-2023 by Arjan van Vught mailto:info@gd32-dmx.org * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal diff --git a/lib-hal/rtc/i2c/hwclockrtc.cpp b/lib-hal/rtc/i2c/hwclockrtc.cpp index 892d2c202..ec1e226f0 100644 --- a/lib-hal/rtc/i2c/hwclockrtc.cpp +++ b/lib-hal/rtc/i2c/hwclockrtc.cpp @@ -2,7 +2,7 @@ * @file hwclockrtc.cpp * */ -/* Copyright (C) 2020-2024 by Arjan van Vught mailto:info@orangepi-dmx.nl +/* Copyright (C) 2020-2024 by Arjan van Vught mailto:info@gd32-dmx.org * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -23,6 +23,19 @@ * THE SOFTWARE. */ +/** + * MCP7941X: It has specific control bits like the Start Timer (ST) and battery enable (VBATEN). + */ + +/** + * DS3231: Known for its accuracy. + */ + +/** + * PCF8563: The time integrity is checked using the SECONDS_VL bit. + * Alarm: Minute, Hour, Day, Weekday + */ + #include #include @@ -37,75 +50,71 @@ namespace rtc { namespace reg { -static constexpr uint8_t SECONDS = 0x00; -static constexpr uint8_t MINUTES = 0x01; -static constexpr uint8_t HOURS = 0x02; -static constexpr uint8_t DAY = 0x03; -static constexpr uint8_t DATE = 0x04; -static constexpr uint8_t MONTH = 0x05; -static constexpr uint8_t YEAR = 0x06; +static constexpr uint8_t SECONDS = 0x00; +static constexpr uint8_t MINUTES = 0x01; +static constexpr uint8_t HOURS = 0x02; +static constexpr uint8_t WDAY = 0x03; +static constexpr uint8_t MDAY = 0x04; +static constexpr uint8_t MONTH = 0x05; +static constexpr uint8_t YEAR = 0x06; } // namespace reg namespace mcp7941x { namespace reg { -static constexpr uint8_t CONTROL = 0x07; +static constexpr uint8_t CONTROL = 0x07; } // namespace reg namespace bit { -static constexpr uint8_t ST = 0x80; -static constexpr uint8_t VBATEN = 0x08; -static constexpr uint8_t ALM0_EN = 0x10; -static constexpr uint8_t ALMX_IF = (1U << 3); -static constexpr uint8_t ALMX_C0 = (1U << 4); -static constexpr uint8_t ALMX_C1 = (1U << 5); -static constexpr uint8_t ALMX_C2 = (1U << 6); +static constexpr uint8_t ST = 0x80; +static constexpr uint8_t VBATEN = 0x08; +static constexpr uint8_t ALM0_EN = 0x10; +static constexpr uint8_t ALMX_IF = (1U << 3); +static constexpr uint8_t ALMX_C0 = (1U << 4); +static constexpr uint8_t ALMX_C1 = (1U << 5); +static constexpr uint8_t ALMX_C2 = (1U << 6); #ifndef NDEBUG -static constexpr uint8_t ALMX_POL = (1U << 7); +static constexpr uint8_t ALMX_POL = (1U << 7); #endif -static constexpr uint8_t MSK_ALMX_MATCH = (ALMX_C0 | ALMX_C1 | ALMX_C2); +static constexpr uint8_t MSK_ALMX_MATCH = (ALMX_C0 | ALMX_C1 | ALMX_C2); } // namespace bit } // namespace mcp7941x namespace ds3231 { namespace reg { -static constexpr uint8_t ALARM1_SECONDS = 0x07; -static constexpr uint8_t CONTROL = 0x0e; -//static constexpr uint8_t STATUS = 0x0f; +static constexpr uint8_t ALARM1_SECONDS = 0x07; +static constexpr uint8_t CONTROL = 0x0e; } // namespace reg namespace bit { -static constexpr uint8_t A1IE = (1U << 0); -static constexpr uint8_t A2IE = (1U << 1); -static constexpr uint8_t A1F = (1U << 0); -static constexpr uint8_t A2F = (1U << 1); +static constexpr uint8_t A1IE = (1U << 0); +static constexpr uint8_t A2IE = (1U << 1); +static constexpr uint8_t A1F = (1U << 0); +static constexpr uint8_t A2F = (1U << 1); } // namespace bit } // namespace ds3231 namespace pcf8563 { namespace reg { -static constexpr uint8_t CONTROL_STATUS1 = 0x00; -static constexpr uint8_t CONTROL_STATUS2 = 0x01; -static constexpr uint8_t SECONDS = 0x02; -//static constexpr uint8_t MINUTES = 0x03; -//static constexpr uint8_t HOURS = 0x04; -//static constexpr uint8_t DAY = 0x05; -//static constexpr uint8_t WEEKDAY = 0x06; -//static constexpr uint8_t MONTH = 0x07; -static constexpr uint8_t YEAR = 0x08; -static constexpr uint8_t ALARM = 0x09; +static constexpr uint8_t CONTROL_STATUS1 = 0x00; +static constexpr uint8_t CONTROL_STATUS2 = 0x01; +static constexpr uint8_t SECONDS = 0x02; +//static constexpr uint8_t MINUTES = 0x03; +//static constexpr uint8_t HOURS = 0x04; +static constexpr uint8_t MDAY = 0x05; +static constexpr uint8_t WDAY = 0x06; +//static constexpr uint8_t MONTH = 0x07; +static constexpr uint8_t YEAR = 0x08; +static constexpr uint8_t ALARM = 0x09; } // namespace reg namespace bit { -static constexpr uint8_t SEC_VL = (1U << 7); -static constexpr uint8_t AIE = (1U << 1); -static constexpr uint8_t AF = (1U << 3); -static constexpr uint8_t ST2_N = (7U << 5); +static constexpr uint8_t SECONDS_VL = (1U << 7); +static constexpr uint8_t STATUS2_AIE = (1U << 1); ///< alarm interrupt enabled +static constexpr uint8_t STATUS2_AF = (1U << 3); ///< read: alarm flag active } // namespace bit } // namespace pcf8563 namespace i2caddress { -static constexpr uint8_t PCF8563 = 0x51; -static constexpr uint8_t MCP7941X = 0x6F; -static constexpr uint8_t DS3231 = 0x68; +static constexpr uint8_t PCF8563 = 0x51; +static constexpr uint8_t MCP7941X = 0x6F; +static constexpr uint8_t DS3231 = 0x68; } // namespace i2caddress } // namespace rtc -using namespace rtc; - -static void write_register(uint8_t nRegister, uint8_t nValue) { +static void i2c_write_register(const uint8_t nRegister, const uint8_t nValue) { char buffer[2]; buffer[0] = static_cast(nRegister); @@ -114,6 +123,19 @@ static void write_register(uint8_t nRegister, uint8_t nValue) { FUNC_PREFIX(i2c_write(buffer, 2)); } +static void i2c_read_register(const uint8_t nRegister, uint8_t& nValue) { + char buffer[1]; + + buffer[0] = static_cast(nRegister); + + FUNC_PREFIX(i2c_write(buffer, 1)); + FUNC_PREFIX(i2c_read(buffer, 1)); + + nValue = buffer[0]; +} + +using namespace rtc; + void HwClock::RtcProbe() { DEBUG_ENTRY @@ -121,17 +143,14 @@ void HwClock::RtcProbe() { FUNC_PREFIX(i2c_set_baudrate(hal::i2c::NORMAL_SPEED)); - char registers[1]; + uint8_t nValue; #if !defined (CONFIG_RTC_DISABLE_MCP7941X) FUNC_PREFIX(i2c_set_address(i2caddress::MCP7941X)); - registers[0] = reg::YEAR; - // The I2C bus is not stable at cold start? These dummy write/read helps. // This needs some more investigation for what is really happening here. - FUNC_PREFIX(i2c_write(registers, 1)); - FUNC_PREFIX(i2c_read(registers, sizeof(registers) / sizeof(registers[0]))); + i2c_read_register(reg::YEAR, nValue); if (FUNC_PREFIX(i2c_write(nullptr, 0)) == 0) { DEBUG_PUTS("MCP7941X"); @@ -140,12 +159,9 @@ void HwClock::RtcProbe() { m_Type = Type::MCP7941X; m_nAddress = i2caddress::MCP7941X; - registers[0] = reg::SECONDS; - - FUNC_PREFIX(i2c_write(registers, 1)); - FUNC_PREFIX(i2c_read(registers, sizeof(registers) / sizeof(registers[0]))); + i2c_read_register(reg::SECONDS, nValue); - if ((registers[0] & mcp7941x::bit::ST) == 0) { + if ((nValue & mcp7941x::bit::ST) == 0) { DEBUG_PUTS("Start the on-board oscillator"); struct tm RtcTime; @@ -168,10 +184,9 @@ void HwClock::RtcProbe() { #if !defined (CONFIG_RTC_DISABLE_DS3231) FUNC_PREFIX(i2c_set_address(i2caddress::DS3231)); - registers[0] = reg::YEAR; - - FUNC_PREFIX(i2c_write(registers, 1)); - FUNC_PREFIX(i2c_read(registers, sizeof(registers) / sizeof(registers[0]))); + // The I2C bus is not stable at cold start? These dummy write/read helps. + // This needs some more investigation for what is really happening here. + i2c_read_register(reg::YEAR, nValue); if (FUNC_PREFIX(i2c_write(nullptr, 0)) == 0) { DEBUG_PUTS("DS3231"); @@ -202,10 +217,9 @@ void HwClock::RtcProbe() { #if !defined (CONFIG_RTC_DISABLE_PCF8563) FUNC_PREFIX(i2c_set_address(i2caddress::PCF8563)); - registers[0] = pcf8563::reg::YEAR; - - FUNC_PREFIX(i2c_write(registers, 1)); - FUNC_PREFIX(i2c_read(registers, sizeof(registers) / sizeof(registers[0]))); + // The I2C bus is not stable at cold start? These dummy write/read helps. + // This needs some more investigation for what is really happening here. + i2c_read_register(pcf8563::reg::YEAR, nValue); if (FUNC_PREFIX(i2c_write(nullptr, 0)) == 0) { DEBUG_PUTS("PCF8563"); @@ -214,15 +228,15 @@ void HwClock::RtcProbe() { m_Type = Type::PCF8563; m_nAddress = i2caddress::PCF8563; - write_register(pcf8563::reg::CONTROL_STATUS1, 0); - write_register(pcf8563::reg::CONTROL_STATUS2, 0); + i2c_write_register(pcf8563::reg::CONTROL_STATUS1, 0); + i2c_write_register(pcf8563::reg::CONTROL_STATUS2, 0); - registers[0] = pcf8563::reg::SECONDS; - - FUNC_PREFIX(i2c_write(registers, 1)); - FUNC_PREFIX(i2c_read(registers,1)); + i2c_read_register(pcf8563::reg::SECONDS, nValue); - if (registers[0] & pcf8563::bit::SEC_VL) { + // Register seconds has the VL bit + // 0 - clock integrity is guaranteed + // 1 - integrity of the clock information is not guaranteed + if ((nValue & pcf8563::bit::SECONDS_VL) == pcf8563::bit::SECONDS_VL) { DEBUG_PUTS("Integrity of the clock information is not guaranteed"); struct tm RtcTime; @@ -237,12 +251,9 @@ void HwClock::RtcProbe() { RtcSet(&RtcTime); } - registers[0] = pcf8563::reg::SECONDS; - - FUNC_PREFIX(i2c_write(registers, 1)); - FUNC_PREFIX(i2c_read(registers,1)); + i2c_read_register(pcf8563::reg::SECONDS, nValue); - if (registers[0] & pcf8563::bit::SEC_VL) { + if ((nValue & pcf8563::bit::SECONDS_VL) == pcf8563::bit::SECONDS_VL) { DEBUG_PUTS("Clock is not running -> disconnected"); m_bIsConnected = false; } @@ -256,9 +267,11 @@ void HwClock::RtcProbe() { } bool HwClock::RtcSet(const struct tm *pTime) { + DEBUG_ENTRY assert(pTime != nullptr); if (!m_bIsConnected) { + DEBUG_EXIT return false; } @@ -277,14 +290,24 @@ bool HwClock::RtcSet(const struct tm *pTime) { registers[reg::SECONDS] = DEC2BCD(pTime->tm_sec & 0x7f); registers[reg::MINUTES] = DEC2BCD(pTime->tm_min & 0x7f); registers[reg::HOURS] = DEC2BCD(pTime->tm_hour & 0x1f); - registers[reg::DAY] = DEC2BCD(pTime->tm_wday & 0x07); - registers[reg::DATE] = DEC2BCD(pTime->tm_mday & 0x3f); + +#if !defined (CONFIG_RTC_DISABLE_PCF8563) + if (m_Type == Type::PCF8563) { + registers[pcf8563::reg::WDAY - pcf8563::reg::SECONDS] = DEC2BCD(pTime->tm_wday & 0x07); + registers[pcf8563::reg::MDAY - pcf8563::reg::SECONDS] = DEC2BCD(pTime->tm_mday & 0x3f); + } else +#endif + { + registers[reg::WDAY] = DEC2BCD(pTime->tm_wday & 0x07); + registers[reg::MDAY] = DEC2BCD(pTime->tm_mday & 0x3f); + } + registers[reg::MONTH] = DEC2BCD((pTime->tm_mon + 1) & 0x1f); registers[reg::YEAR] = DEC2BCD((pTime->tm_year - 100) & 0xff); if (m_Type == Type::MCP7941X) { registers[reg::SECONDS] |= mcp7941x::bit::ST; - registers[reg::DAY] |= mcp7941x::bit::VBATEN; + registers[reg::WDAY] |= mcp7941x::bit::VBATEN; } if (m_Type == Type::PCF8563) { @@ -297,13 +320,16 @@ bool HwClock::RtcSet(const struct tm *pTime) { FUNC_PREFIX(i2c_set_baudrate(hal::i2c::FULL_SPEED)); FUNC_PREFIX(i2c_write(data, sizeof(data) / sizeof(data[0]))); + DEBUG_EXIT return true; } bool HwClock::RtcGet(struct tm *pTime) { + DEBUG_ENTRY assert(pTime != nullptr); if (!m_bIsConnected) { + DEBUG_EXIT return false; } @@ -323,8 +349,18 @@ bool HwClock::RtcGet(struct tm *pTime) { pTime->tm_sec = BCD2DEC(registers[reg::SECONDS] & 0x7f); pTime->tm_min = BCD2DEC(registers[reg::MINUTES] & 0x7f); pTime->tm_hour = BCD2DEC(registers[reg::HOURS] & 0x3f); - pTime->tm_wday = BCD2DEC(registers[reg::DAY] & 0x07); - pTime->tm_mday = BCD2DEC(registers[reg::DATE] & 0x3f); + +#if !defined (CONFIG_RTC_DISABLE_PCF8563) + if (m_Type == Type::PCF8563) { + pTime->tm_wday = BCD2DEC(registers[pcf8563::reg::WDAY - pcf8563::reg::SECONDS] & 0x07); + pTime->tm_mday = BCD2DEC(registers[pcf8563::reg::MDAY - pcf8563::reg::SECONDS] & 0x3f); + } else +#endif + { + pTime->tm_wday = BCD2DEC(registers[reg::WDAY] & 0x07); + pTime->tm_mday = BCD2DEC(registers[reg::MDAY] & 0x3f); + } + pTime->tm_mon = BCD2DEC(registers[reg::MONTH] & 0x1f) - 1; pTime->tm_year = BCD2DEC(registers[reg::YEAR]) + 100; @@ -337,6 +373,7 @@ bool HwClock::RtcGet(struct tm *pTime) { pTime->tm_year, pTime->tm_wday); + DEBUG_EXIT return true; } @@ -425,6 +462,7 @@ bool HwClock::RtcSetAlarm(const struct tm *pTime) { FUNC_PREFIX(i2c_write(registers, sizeof(registers) / sizeof(registers[0]))); if (m_bRtcAlarmEnabled) { + DEBUG_PUTS("Alarm is enabled"); registers[0] = ds3231::reg::CONTROL; registers[1] |= ds3231::bit::A1IE; FUNC_PREFIX(i2c_write(registers, 2)); @@ -607,20 +645,20 @@ int HwClock::MCP794xxAlarmWeekday(struct tm *pTime) { } void HwClock::PCF8563GetAlarmMode() { + DEBUG_ENTRY assert(m_Type == rtc::Type::PCF8563); - char data[1]; - - data[0] = pcf8563::reg::CONTROL_STATUS2; + uint8_t nValue; + i2c_read_register(pcf8563::reg::CONTROL_STATUS2, nValue); - FUNC_PREFIX(i2c_write(data, 1)); - FUNC_PREFIX(i2c_read(data, sizeof(data) / sizeof(data[0]))); + m_bRtcAlarmEnabled = nValue & pcf8563::bit::STATUS2_AIE; + m_bRtcAlarmPending = nValue & pcf8563::bit::STATUS2_AF; - m_bRtcAlarmEnabled = data[0] & pcf8563::bit::AIE; - m_bRtcAlarmPending = data[0] & pcf8563::bit::AF; + DEBUG_EXIT } void HwClock::PCF8563SetAlarmMode() { + DEBUG_ENTRY assert(m_Type == rtc::Type::PCF8563); char data[2]; @@ -631,14 +669,16 @@ void HwClock::PCF8563SetAlarmMode() { FUNC_PREFIX(i2c_read(&data[1], 1)); if (m_bRtcAlarmEnabled) { - data[1] |= pcf8563::bit::AIE; + DEBUG_PUTS("Alarm is enabled"); + data[1] |= pcf8563::bit::STATUS2_AIE; } else { - data[1] &= static_cast(~pcf8563::bit::AIE); + data[1] &= static_cast(~pcf8563::bit::STATUS2_AIE); } - data[1] &= static_cast(~pcf8563::bit::AF | pcf8563::bit::ST2_N); - data[0] = pcf8563::reg::CONTROL_STATUS2; + data[1] &= static_cast(~pcf8563::bit::STATUS2_AF); FUNC_PREFIX(i2c_write(data, 2)); + + DEBUG_EXIT } diff --git a/lib-hal/rtc/json_rtc.cpp b/lib-hal/rtc/json_rtc.cpp index 443dd51af..938a6a52e 100755 --- a/lib-hal/rtc/json_rtc.cpp +++ b/lib-hal/rtc/json_rtc.cpp @@ -44,6 +44,8 @@ static void staticCallbackFunction([[maybe_unused]] void *p, const char *s) { assert(p == nullptr); assert(s != nullptr); + DEBUG_PUTS(s); + uint32_t nLength = iso8601FormatSize; if (Sscan::Char(s, "alarm" , iso8601Format, nLength) == Sscan::OK) { @@ -55,6 +57,8 @@ static void staticCallbackFunction([[maybe_unused]] void *p, const char *s) { nLength = sizeof(action) - 1; if (Sscan::Char(s, "action" , action, nLength) == Sscan::OK) { + DEBUG_PUTS("action"); + if (strncmp(action, "hctosys", nLength) == 0) { HwClock::Get()->HcToSys(); return; @@ -71,6 +75,8 @@ static void staticCallbackFunction([[maybe_unused]] void *p, const char *s) { uint8_t nValue8; if (Sscan::Uint8(s, "enable", nValue8) == Sscan::OK) { + DEBUG_PUTS("enable"); + HwClock::Get()->AlarmEnable(nValue8 != 0); return; } diff --git a/lib-input/.settings/language.settings.xml b/lib-input/.settings/language.settings.xml index 956b700d0..b761a2025 100644 --- a/lib-input/.settings/language.settings.xml +++ b/lib-input/.settings/language.settings.xml @@ -5,7 +5,7 @@ - + @@ -17,7 +17,7 @@ - + @@ -29,7 +29,7 @@ - + diff --git a/lib-jamstapl/.settings/language.settings.xml b/lib-jamstapl/.settings/language.settings.xml index 588f95fb1..1feceea34 100644 --- a/lib-jamstapl/.settings/language.settings.xml +++ b/lib-jamstapl/.settings/language.settings.xml @@ -5,7 +5,7 @@ - + diff --git a/lib-l6470/.settings/language.settings.xml b/lib-l6470/.settings/language.settings.xml index 077a3f733..37b3eb25e 100644 --- a/lib-l6470/.settings/language.settings.xml +++ b/lib-l6470/.settings/language.settings.xml @@ -5,7 +5,7 @@ - + @@ -17,7 +17,7 @@ - + @@ -29,7 +29,7 @@ - + diff --git a/lib-l6470dmx/.settings/language.settings.xml b/lib-l6470dmx/.settings/language.settings.xml index 1bea8cbc6..beeb54166 100644 --- a/lib-l6470dmx/.settings/language.settings.xml +++ b/lib-l6470dmx/.settings/language.settings.xml @@ -5,7 +5,7 @@ - + @@ -17,7 +17,7 @@ - + @@ -29,7 +29,7 @@ - + diff --git a/lib-lightset/.settings/language.settings.xml b/lib-lightset/.settings/language.settings.xml index 0daee9f62..a04cfb7f2 100644 --- a/lib-lightset/.settings/language.settings.xml +++ b/lib-lightset/.settings/language.settings.xml @@ -5,7 +5,7 @@ - + @@ -17,7 +17,7 @@ - + diff --git a/lib-ltc/.settings/language.settings.xml b/lib-ltc/.settings/language.settings.xml index 6f1cc345a..44936195d 100644 --- a/lib-ltc/.settings/language.settings.xml +++ b/lib-ltc/.settings/language.settings.xml @@ -5,7 +5,7 @@ - + diff --git a/lib-midi/.settings/language.settings.xml b/lib-midi/.settings/language.settings.xml index fefa6fa4e..74fd2a9f4 100644 --- a/lib-midi/.settings/language.settings.xml +++ b/lib-midi/.settings/language.settings.xml @@ -5,7 +5,7 @@ - + @@ -17,7 +17,7 @@ - + diff --git a/lib-network/.cproject b/lib-network/.cproject index d6c35f114..03c1fab6a 100644 --- a/lib-network/.cproject +++ b/lib-network/.cproject @@ -112,6 +112,7 @@ + @@ -143,6 +144,7 @@ + @@ -175,6 +177,8 @@ + + @@ -275,6 +279,8 @@ + + @@ -308,6 +314,7 @@ + @@ -459,6 +466,7 @@ +