Implement read/write indication on the fault LEDs

Conflicts:
	Downstream/Inc/build_config.h
	Downstream/Src/downstream_msc.c
	Downstream/Src/led.c
	Upstream/Inc/build_config.h
	Upstream/Src/led.c
USG_0.9
Robert Fisk 5 years ago
parent 151ae57b14
commit 1277532140

@ -19,5 +19,7 @@
#define CONFIG_KEYBOARD_ENABLED
#define CONFIG_MOUSE_ENABLED
#define CONFIG_READ_FLASH_TIME_MS 3000 //Enable read LED flashes for the specified length of time
#endif /* INC_BUILD_CONFIG_H_ */

@ -22,7 +22,8 @@ typedef enum
LED_STATUS_OFF,
LED_STATUS_FLASH_ERROR,
LED_STATUS_FLASH_UNSUPPORTED,
LED_STATUS_FLASH_BOTDETECT
LED_STATUS_FLASH_BOTDETECT,
LED_STATUS_FLASH_READWRITE
}
LedStatusTypeDef;
@ -36,8 +37,10 @@ void LED_Tick(void);
#define LED_ERROR_BLINK_MS 100
#define LED_UNSUPPORTED_BLINK_MS 500
#define LED_BOTDETECT_BLINK_MS 100
#define LED_BOTDETECT_OFF_MS (1000 - (LED_BOTDETECT_BLINK_MS * 3)) //Two flashes, total period = 1 sec
#define LED_BOTDETECT_ON_MS 100
#define LED_BOTDETECT_OFF_MS (1000 - (LED_BOTDETECT_ON_MS * 3)) //Two flashes, total period = 1 sec
#define LED_READWRITE_ON_MS 10
#define LED_READWRITE_OFF_MS 30

@ -16,6 +16,7 @@
#include "downstream_spi.h"
#include "usbh_msc.h"
#include "build_config.h"
#include "led.h"
#ifdef CONFIG_MASS_STORAGE_ENABLED
@ -164,6 +165,7 @@ static void Downstream_MSC_PacketProcessor_BeginRead(DownstreamPacketTypeDef* re
return;
}
LED_SetState(LED_STATUS_FLASH_READWRITE);
readBlockAddress = *(uint64_t*)&(receivedPacket->Data[0]);
readBlockCount = *(uint32_t*)&(receivedPacket->Data[8]);
readByteCount = readBlockCount * MSC_Handle->unit[MSC_FIXED_LUN].capacity.block_size;

@ -14,6 +14,7 @@
#include "board_config.h"
uint32_t FaultLedCounter;
uint32_t ReadWriteFlashEndTime;
LedStatusTypeDef FaultLedState;
uint16_t FaultLedOnMs;
@ -27,15 +28,14 @@ uint8_t FaultLedOutputState;
void LED_Init(void)
{
FAULT_LED_ON;
ReadWriteFlashEndTime = 0;
FaultLedState = LED_STATUS_STARTUP;
}
void LED_SetState(LedStatusTypeDef newState)
{
FaultLedState = newState;
switch (FaultLedState)
switch (newState)
{
case LED_STATUS_OFF:
FaultLedCounter = UINT32_MAX;
@ -51,16 +51,34 @@ void LED_SetState(LedStatusTypeDef newState)
break;
case LED_STATUS_FLASH_BOTDETECT:
FaultLedOnMs = LED_BOTDETECT_BLINK_MS;
FaultLedOnMs = LED_BOTDETECT_ON_MS;
FaultLedOffMs = LED_BOTDETECT_OFF_MS;
FaultLedBlinkCount = 2;
break;
case LED_STATUS_FLASH_READWRITE:
#ifdef CONFIG_READ_FLASH_TIME_MS
if (FaultLedState == LED_STATUS_OFF)
{
FaultLedOnMs = LED_READWRITE_ON_MS;
FaultLedOffMs = LED_READWRITE_OFF_MS;
FaultLedBlinkCount = 1;
ReadWriteFlashEndTime = HAL_GetTick() + CONFIG_READ_FLASH_TIME_MS;
}
else
#endif
{
newState = FaultLedState; //Don't override other active states
}
break;
default:
FaultLedOnMs = LED_ERROR_BLINK_MS; //Everything else is LED_STATUS_ERROR
FaultLedOffMs = LED_ERROR_BLINK_MS;
FaultLedBlinkCount = 1;
}
FaultLedState = newState;
}
@ -77,6 +95,17 @@ void LED_Tick(void)
return;
}
#ifdef CONFIG_READ_FLASH_TIME_MS
if (FaultLedState == LED_STATUS_FLASH_READWRITE)
{
if ((int32_t)(HAL_GetTick() - ReadWriteFlashEndTime) > 0)
{
LED_SetState(LED_STATUS_OFF);
return;
}
}
#endif
if (FaultLedOutputState)
{
if (FaultLedCounter++ >= FaultLedOnMs) //Check to turn LED off

@ -22,6 +22,9 @@
#define CONFIG_MOUSE_ENABLED
#define CONFIG_MOUSE_BOT_DETECT_ENABLED
#define CONFIG_WRITE_FLASH_TIME_MS 3000 //Enable write LED flashes for the specified length of time
//Configure keyboard bot detection here:
#ifdef CONFIG_KEYBOARD_BOT_DETECT_ENABLED

@ -22,7 +22,8 @@ typedef enum
LED_STATUS_OFF,
LED_STATUS_FLASH_ERROR,
LED_STATUS_FLASH_UNSUPPORTED,
LED_STATUS_FLASH_BOTDETECT
LED_STATUS_FLASH_BOTDETECT,
LED_STATUS_FLASH_READWRITE
}
LedStatusTypeDef;
@ -36,8 +37,10 @@ void LED_Tick(void);
#define LED_ERROR_BLINK_MS 100
#define LED_UNSUPPORTED_BLINK_MS 500
#define LED_BOTDETECT_BLINK_MS 100
#define LED_BOTDETECT_OFF_MS (1000 - (LED_BOTDETECT_BLINK_MS * 3)) //Two flashes, total period = 1 sec
#define LED_BOTDETECT_ON_MS 100
#define LED_BOTDETECT_OFF_MS (1000 - (LED_BOTDETECT_ON_MS * 3)) //Two flashes, total period = 1 sec
#define LED_READWRITE_ON_MS 10
#define LED_READWRITE_OFF_MS 30
#endif /* INC_LED_H_ */

@ -14,6 +14,7 @@
#include "board_config.h"
uint32_t FaultLedCounter;
uint32_t ReadWriteFlashEndTime;
LedStatusTypeDef FaultLedState;
uint16_t FaultLedOnMs;
@ -27,15 +28,14 @@ uint8_t FaultLedOutputState;
void LED_Init(void)
{
FAULT_LED_ON;
ReadWriteFlashEndTime = 0;
FaultLedState = LED_STATUS_STARTUP;
}
void LED_SetState(LedStatusTypeDef newState)
{
FaultLedState = newState;
switch (FaultLedState)
switch (newState)
{
case LED_STATUS_OFF:
FaultLedCounter = UINT32_MAX;
@ -51,16 +51,34 @@ void LED_SetState(LedStatusTypeDef newState)
break;
case LED_STATUS_FLASH_BOTDETECT:
FaultLedOnMs = LED_BOTDETECT_BLINK_MS;
FaultLedOnMs = LED_BOTDETECT_ON_MS;
FaultLedOffMs = LED_BOTDETECT_OFF_MS;
FaultLedBlinkCount = 2;
break;
case LED_STATUS_FLASH_READWRITE:
#ifdef CONFIG_WRITE_FLASH_TIME_MS
if (FaultLedState == LED_STATUS_OFF)
{
FaultLedOnMs = LED_READWRITE_ON_MS;
FaultLedOffMs = LED_READWRITE_OFF_MS;
FaultLedBlinkCount = 1;
ReadWriteFlashEndTime = HAL_GetTick() + CONFIG_WRITE_FLASH_TIME_MS;
}
else
#endif
{
newState = FaultLedState; //Don't override other active states
}
break;
default:
FaultLedOnMs = LED_ERROR_BLINK_MS; //Everything else is LED_STATUS_ERROR
FaultLedOffMs = LED_ERROR_BLINK_MS;
FaultLedBlinkCount = 1;
}
FaultLedState = newState;
}
@ -77,6 +95,17 @@ void LED_Tick(void)
return;
}
#ifdef CONFIG_WRITE_FLASH_TIME_MS
if (FaultLedState == LED_STATUS_FLASH_READWRITE)
{
if ((int32_t)(HAL_GetTick() - ReadWriteFlashEndTime) > 0)
{
LED_SetState(LED_STATUS_OFF);
return;
}
}
#endif
if (FaultLedOutputState)
{
if (FaultLedCounter++ >= FaultLedOnMs) //Check to turn LED off

@ -298,6 +298,7 @@ HAL_StatusTypeDef Upstream_MSC_BeginWrite(UpstreamMSCCallbackTypeDef callback,
return HAL_ERROR;
}
LED_SetState(LED_STATUS_FLASH_READWRITE);
BlockStart = writeBlockStart;
BlockCount = writeBlockCount;
BeginWriteCallback = callback;

Loading…
Cancel
Save