void ModeSelect::StartModeSelect(void)
{
  mode_new = 0;
  mode_act = 0;
  blinkcnt = 0;
  timecnt = 0;

  EELIB_Command command;
  EELIB_Result result;
  uint8_t buf8;


  button_state = ReadButton();
  button_debounce = 0;

  command[0] = EELIB_IAP_COMMAND_EEPROM_READ;
  command[1] = 0; // Eeprom address
  command[2] = (uint32_t) &buf8;
  command[3] = 1; // Read length
  command[4] = SystemCoreClock / 1000;
  EELIB_entry(command, result);

  if (result[0] != EELIB_IAP_STATUS_CMD_SUCCESS) {
    buf8 = 0;
  }

  if (buf8 >= MODENUM)
    buf8 = 0;
  mode_new = buf8;
  mode_act = buf8;
  SetLeds();
}
Example #2
0
uint8_t EEPROM_Write(uint16_t AddressToWrite, void* DataArray, uint16_t BytesToWrite)
{
	IAP_Result[0] = 0;

	//TODO: check to make sure the address is valid

#ifdef USE_EEPROM_LIB
	IAP_Command[0] = EELIB_IAP_COMMAND_EEPROM_WRITE;	//EEPROM library write command
#else
	IAP_Command[0] = IAP_EEPROM_WRITE;					//IAP EEPROM write command
#endif
	IAP_Command[1] = (uint32_t)AddressToWrite;			//EEPROM address to write to
	IAP_Command[2] = (uint32_t)DataArray;				//RAM address of the data to write
	IAP_Command[3] = (uint32_t)BytesToWrite;			//Number of bytes to write
	IAP_Command[4] = SystemCoreClock/1000;				//System clock frequency in kHz

#ifdef USE_EEPROM_LIB
	EELIB_entry(IAP_Command, IAP_Result);
#else
	vPortEnterCritical();
	iap_entry(IAP_Command, IAP_Result);
	vPortExitCritical();
#endif

	return (uint8_t)IAP_Result[0];
}
// alle 10 ms aufrufen
bool ModeSelect::DoModeSelect(void)
{
  if (ButtonDebounce())
  {
    mode_new = mode_new+1;
    if (mode_new >= MODENUM)
      mode_new = 0;
    blinkcnt = 7;
    timecnt = MODELED_HPRD;
    SetLeds();
  } else if (blinkcnt != 0)
  {
    if (timecnt > 0)
      timecnt--;
    if (timecnt == 0)
    {
      blinkcnt--;
      if (blinkcnt > 0)
      {
        timecnt = MODELED_HPRD;
        SetSingleLed(mode_new, (blinkcnt & 1) != 0);
      } else {
        if (mode_act != mode_new)
        {
          mode_act = mode_new;
          SetSingleLed(mode_new, true);
          // Neuen Modus noch abspeichern.
          uint32_t command[5], result[4];
          uint8_t buf8 = mode_act;
          command[0] = EELIB_IAP_COMMAND_EEPROM_WRITE;
          command[1] = 0; // Eeprom address
          command[2] = (uint32_t) &buf8;
          command[3] = 1; // Write length
          command[4] = SystemCoreClock / 1000;
          EELIB_entry(command, result);
          if (result[0] != EELIB_IAP_STATUS_CMD_SUCCESS) {
            // doof das...
          }

          return true;
        }
      }
    } else {
      // nichts zu tun
    }
  } else {
    // nichts zu tun
  }
  return false;
}
Example #4
0
uint8_t EEPROM_Read(uint16_t AddressToRead, void* DataArray, uint16_t BytesToRead)
{
	IAP_Result[0] = 0;

#ifdef USE_EEPROM_LIB
	IAP_Command[0] = EELIB_IAP_COMMAND_EEPROM_READ;		//EEPROM library read command
#else
	IAP_Command[0] = IAP_EEPROM_READ;					//IAP EEPROM read command
#endif
	IAP_Command[1] = (uint32_t)AddressToRead;			//EEPROM address to read from
	IAP_Command[2] = (uint32_t)DataArray;				//RAM address to copy the EEPROM data to
	IAP_Command[3] = (uint32_t)BytesToRead;				//Number of bytes to read
	IAP_Command[4] = SystemCoreClock/1000;				//System clock frequency in kHz

#ifdef USE_EEPROM_LIB
	EELIB_entry(IAP_Command, IAP_Result);
#else
	vPortEnterCritical();
	iap_entry(IAP_Command, IAP_Result);
	vPortExitCritical();
#endif

	return (uint8_t)IAP_Result[0];
}