Browse Source

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_1.0
Robert Fisk 2 years ago
parent
commit
bbad577d43
  1. 2
      Downstream/Inc/build_config.h
  2. 9
      Downstream/Inc/led.h
  3. 2
      Downstream/Src/downstream_msc.c
  4. 37
      Downstream/Src/led.c
  5. 3
      Upstream/Inc/build_config.h
  6. 9
      Upstream/Inc/led.h
  7. 37
      Upstream/Src/led.c
  8. 1
      Upstream/Src/upstream_msc.c

2
Downstream/Inc/build_config.h

@ -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_ */

9
Downstream/Inc/led.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

2
Downstream/Src/downstream_msc.c

@ -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;

37
Downstream/Src/led.c

@ -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

3
Upstream/Inc/build_config.h

@ -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

9
Upstream/Inc/led.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
#endif /* INC_LED_H_ */

37
Upstream/Src/led.c

@ -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

1
Upstream/Src/upstream_msc.c

@ -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