Fixed ISR definition conflict in the XPLAIN bridge between the software UART and...
[pub/USBasp.git] / Projects / TempDataLogger / TempDataLogger.c
index e7c7c76..bf5fd39 100644 (file)
@@ -89,7 +89,7 @@ uint8_t LoggingInterval500MS_SRAM;
 /** Total number of 500ms logging ticks elapsed since the last log value was recorded */
 uint16_t CurrentLoggingTicks;
 
 /** Total number of 500ms logging ticks elapsed since the last log value was recorded */
 uint16_t CurrentLoggingTicks;
 
-/** FAT Fs structure to hold the internal state of the FAT driver for the dataflash contents. */
+/** FAT Fs structure to hold the internal state of the FAT driver for the Dataflash contents. */
 FATFS DiskFATState;
 
 /** FAT Fs structure to hold a FAT file handle for the log data write destination. */
 FATFS DiskFATState;
 
 /** FAT Fs structure to hold a FAT file handle for the log data write destination. */
@@ -105,10 +105,10 @@ ISR(TIMER1_COMPA_vect, ISR_BLOCK)
        if (CurrentLoggingTicks++ < LoggingInterval500MS_SRAM)
          return;
            
        if (CurrentLoggingTicks++ < LoggingInterval500MS_SRAM)
          return;
            
-       LEDs_SetAllLEDs(LEDMASK_USB_BUSY);
-
        /* Reset log tick counter to prepare for next logging interval */
        CurrentLoggingTicks = 0;
        /* Reset log tick counter to prepare for next logging interval */
        CurrentLoggingTicks = 0;
+
+       LEDs_SetAllLEDs(LEDMASK_USB_BUSY);
        
        /* Only log when not connected to a USB host */
        if (USB_DeviceState == DEVICE_STATE_Unattached)
        
        /* Only log when not connected to a USB host */
        if (USB_DeviceState == DEVICE_STATE_Unattached)
@@ -146,7 +146,7 @@ int main(void)
        if (LoggingInterval500MS_SRAM == 0xFF)
          LoggingInterval500MS_SRAM = DEFAULT_LOG_INTERVAL;
 
        if (LoggingInterval500MS_SRAM == 0xFF)
          LoggingInterval500MS_SRAM = DEFAULT_LOG_INTERVAL;
 
-       /* Mount and open the log file on the dataflash FAT partition */
+       /* Mount and open the log file on the Dataflash FAT partition */
        OpenLogFile();
 
        LEDs_SetAllLEDs(LEDMASK_USB_NOTREADY);
        OpenLogFile();
 
        LEDs_SetAllLEDs(LEDMASK_USB_NOTREADY);
@@ -201,7 +201,7 @@ void SetupHardware(void)
        /* Hardware Initialization */
        LEDs_Init();
        SPI_Init(SPI_SPEED_FCPU_DIV_2 | SPI_SCK_LEAD_FALLING | SPI_SAMPLE_TRAILING | SPI_MODE_MASTER);
        /* Hardware Initialization */
        LEDs_Init();
        SPI_Init(SPI_SPEED_FCPU_DIV_2 | SPI_SCK_LEAD_FALLING | SPI_SAMPLE_TRAILING | SPI_MODE_MASTER);
-       ADC_Init(ADC_REFERENCE_AVCC | ADC_FREE_RUNNING | ADC_PRESCALE_128);
+       ADC_Init(ADC_FREE_RUNNING | ADC_PRESCALE_128);
        Temperature_Init();
        Dataflash_Init();
        USB_Init();
        Temperature_Init();
        Dataflash_Init();
        USB_Init();
@@ -230,20 +230,19 @@ void EVENT_USB_Device_Disconnect(void)
 {
        LEDs_SetAllLEDs(LEDMASK_USB_NOTREADY);
        
 {
        LEDs_SetAllLEDs(LEDMASK_USB_NOTREADY);
        
-       /* Mount and open the log file on the dataflash FAT partition */
+       /* Mount and open the log file on the Dataflash FAT partition */
        OpenLogFile();
 }
 
 /** Event handler for the library USB Configuration Changed event. */
 void EVENT_USB_Device_ConfigurationChanged(void)
 {
        OpenLogFile();
 }
 
 /** Event handler for the library USB Configuration Changed event. */
 void EVENT_USB_Device_ConfigurationChanged(void)
 {
-       LEDs_SetAllLEDs(LEDMASK_USB_READY);
+       bool ConfigSuccess = true;
+
+       ConfigSuccess &= MS_Device_ConfigureEndpoints(&Disk_MS_Interface);
+       ConfigSuccess &= HID_Device_ConfigureEndpoints(&Generic_HID_Interface);
 
 
-       if (!(MS_Device_ConfigureEndpoints(&Disk_MS_Interface)))
-         LEDs_SetAllLEDs(LEDMASK_USB_ERROR);
-         
-       if (!(HID_Device_ConfigureEndpoints(&Generic_HID_Interface)))
-         LEDs_SetAllLEDs(LEDMASK_USB_ERROR);   
+       LEDs_SetAllLEDs(ConfigSuccess ? LEDMASK_USB_READY : LEDMASK_USB_ERROR);
 }
 
 /** Event handler for the library USB Unhandled Control Request event. */
 }
 
 /** Event handler for the library USB Unhandled Control Request event. */
@@ -273,14 +272,17 @@ bool CALLBACK_MS_Device_SCSICommandReceived(USB_ClassInfo_MS_Device_t* const MSI
  *  \param[in]     HIDInterfaceInfo  Pointer to the HID class interface configuration structure being referenced
  *  \param[in,out] ReportID    Report ID requested by the host if non-zero, otherwise callback should set to the 
  *                             generated report ID
  *  \param[in]     HIDInterfaceInfo  Pointer to the HID class interface configuration structure being referenced
  *  \param[in,out] ReportID    Report ID requested by the host if non-zero, otherwise callback should set to the 
  *                             generated report ID
- *  \param[in]     ReportType  Type of the report to create, either REPORT_ITEM_TYPE_In or REPORT_ITEM_TYPE_Feature
+ *  \param[in]     ReportType  Type of the report to create, either HID_REPORT_ITEM_In or HID_REPORT_ITEM_Feature
  *  \param[out]    ReportData  Pointer to a buffer where the created report should be stored
  *  \param[out]    ReportSize  Number of bytes written in the report (or zero if no report is to be sent
  *
  *  \return Boolean true to force the sending of the report, false to let the library determine if it needs to be sent
  */
  *  \param[out]    ReportData  Pointer to a buffer where the created report should be stored
  *  \param[out]    ReportSize  Number of bytes written in the report (or zero if no report is to be sent
  *
  *  \return Boolean true to force the sending of the report, false to let the library determine if it needs to be sent
  */
-bool CALLBACK_HID_Device_CreateHIDReport(USB_ClassInfo_HID_Device_t* const HIDInterfaceInfo, uint8_t* const ReportID,
-                                         const uint8_t ReportType, void* ReportData, uint16_t* const ReportSize)
+bool CALLBACK_HID_Device_CreateHIDReport(USB_ClassInfo_HID_Device_t* const HIDInterfaceInfo,
+                                         uint8_t* const ReportID,
+                                         const uint8_t ReportType,
+                                         void* ReportData,
+                                         uint16_t* const ReportSize)
 {
        Device_Report_t* ReportParams = (Device_Report_t*)ReportData;
 
 {
        Device_Report_t* ReportParams = (Device_Report_t*)ReportData;
 
@@ -297,12 +299,15 @@ bool CALLBACK_HID_Device_CreateHIDReport(USB_ClassInfo_HID_Device_t* const HIDIn
  *
  *  \param[in] HIDInterfaceInfo  Pointer to the HID class interface configuration structure being referenced
  *  \param[in] ReportID    Report ID of the received report from the host
  *
  *  \param[in] HIDInterfaceInfo  Pointer to the HID class interface configuration structure being referenced
  *  \param[in] ReportID    Report ID of the received report from the host
- *  \param[in] ReportType  The type of report that the host has sent, either REPORT_ITEM_TYPE_Out or REPORT_ITEM_TYPE_Feature
+ *  \param[in] ReportType  The type of report that the host has sent, either HID_REPORT_ITEM_Out or HID_REPORT_ITEM_Feature
  *  \param[in] ReportData  Pointer to a buffer where the created report has been stored
  *  \param[in] ReportSize  Size in bytes of the received HID report
  */
  *  \param[in] ReportData  Pointer to a buffer where the created report has been stored
  *  \param[in] ReportSize  Size in bytes of the received HID report
  */
-void CALLBACK_HID_Device_ProcessHIDReport(USB_ClassInfo_HID_Device_t* const HIDInterfaceInfo, const uint8_t ReportID,
-                                          const uint8_t ReportType, const void* ReportData, const uint16_t ReportSize)
+void CALLBACK_HID_Device_ProcessHIDReport(USB_ClassInfo_HID_Device_t* const HIDInterfaceInfo,
+                                          const uint8_t ReportID,
+                                          const uint8_t ReportType,
+                                          const void* ReportData,
+                                          const uint16_t ReportSize)
 {
        Device_Report_t* ReportParams = (Device_Report_t*)ReportData;
        
 {
        Device_Report_t* ReportParams = (Device_Report_t*)ReportData;