/* Private variables ---------------------------------------------------------*/
PCD_HandleTypeDef hpcd_USB_FS;
+volatile byte led_trigger;
/* USER CODE BEGIN PV */
/* Private variables ---------------------------------------------------------*/
/* USER CODE BEGIN 0 */
+static void process_packet(void)
+{
+ uint cmd = get_u32_be(rx_packet);
+ uint arg = get_u32_be(rx_packet+4);
+ debug_printf("<< cmd %08x %08x\n", cmd, arg);
+
+ memset(tx_packet, 0, sizeof(tx_packet));
+ put_u32_be(tx_packet, 1);
+
+ switch (cmd)
+ {
+ case 1:
+ if (arg < 16)
+ {
+ if (arg & 1)
+ LL_GPIO_ResetOutputPin(SSR1_GPIO_Port, SSR1_Pin);
+ else
+ LL_GPIO_SetOutputPin(SSR1_GPIO_Port, SSR1_Pin);
+ if (arg & 2)
+ LL_GPIO_ResetOutputPin(SSR2_GPIO_Port, SSR2_Pin);
+ else
+ LL_GPIO_SetOutputPin(SSR2_GPIO_Port, SSR2_Pin);
+ if (arg & 4)
+ LL_GPIO_ResetOutputPin(SSR3_GPIO_Port, SSR3_Pin);
+ else
+ LL_GPIO_SetOutputPin(SSR3_GPIO_Port, SSR3_Pin);
+ if (arg & 8)
+ LL_GPIO_ResetOutputPin(SSR4_GPIO_Port, SSR4_Pin);
+ else
+ LL_GPIO_SetOutputPin(SSR4_GPIO_Port, SSR4_Pin);
+ put_u32_be(tx_packet, 0);
+ }
+ break;
+ }
+
+ debug_printf(">> status %08x\n", get_u32_be(tx_packet));
+}
+
/* USER CODE END 0 */
/**
/* USER CODE BEGIN WHILE */
while (1)
{
- static byte led_state;
- if (led_state)
+ if (led_trigger)
{
- LL_GPIO_SetOutputPin(LED_GPIO_Port, LED_Pin);
- LL_GPIO_SetOutputPin(SSR1_GPIO_Port, SSR1_Pin);
- LL_GPIO_SetOutputPin(SSR2_GPIO_Port, SSR2_Pin);
- LL_GPIO_SetOutputPin(SSR3_GPIO_Port, SSR3_Pin);
- LL_GPIO_SetOutputPin(SSR4_GPIO_Port, SSR4_Pin);
- }
- else
- {
- LL_GPIO_ResetOutputPin(LED_GPIO_Port, LED_Pin);
- static byte xxx;
- switch (xxx)
- {
- case 0:
- LL_GPIO_ResetOutputPin(SSR1_GPIO_Port, SSR1_Pin);
- break;
- case 1:
- LL_GPIO_ResetOutputPin(SSR2_GPIO_Port, SSR2_Pin);
- break;
- case 2:
- LL_GPIO_ResetOutputPin(SSR3_GPIO_Port, SSR3_Pin);
- break;
- case 3:
- LL_GPIO_ResetOutputPin(SSR4_GPIO_Port, SSR4_Pin);
- break;
- }
- xxx = (xxx+1) % 4;
+ led_trigger = 0;
+ static byte led_state;
+ if (led_state)
+ LL_GPIO_SetOutputPin(LED_GPIO_Port, LED_Pin);
+ else
+ LL_GPIO_ResetOutputPin(LED_GPIO_Port, LED_Pin);
+ led_state ^= 1;
}
- led_state ^= 1;
if (rx_packet_state == 1 && !tx_packet_state)
{
tx_packet_state = 1;
- put_u32_be(tx_packet, 42);
+ process_packet();
usb_ep_send(&usb, 0x82, tx_packet, 12);
rx_packet_state = 0;
usb_ep_receive(&usb, 0x01, rx_packet, 64);
}
+#if 0
static int cnt;
debug_printf("Counter = %d\n", cnt);
cnt++;
+#endif
- //__WFI();
- LL_mDelay(1000);
+ __WFI();
+ // LL_mDelay(1000);
/* USER CODE END WHILE */