+// main.c
+
+extern byte rx_display[8];
+extern volatile byte rx_display_ready;
+
// display.c
void display_init(void);
void display_counter(uint cnt);
+void display_buffer(byte *buf);
display_data_end();
}
}
+
+void display_buffer(byte *buf)
+{
+ for (uint p=0; p<4; p++)
+ {
+ display_cmd(SSD1306_SETSTARTPAGE + p);
+ display_cmd(SSD1306_SETHIGHCOLUMN);
+ display_cmd(SSD1306_SETLOWCOLUMN);
+ display_data_start();
+ for (uint i=0; i<5; i++)
+ {
+ uint ch = buf[i];
+ if (ch <= 10)
+ {
+ for (uint j=0; j<23; j++)
+ {
+ byte x = Gentium23x32[(23*4+1)*ch + 1 + 4*j + p];
+ display_data(x);
+ }
+ }
+ else
+ {
+ for (uint j=0; j<23; j++)
+ display_data(0);
+ }
+ display_data(0);
+ display_data(0);
+ display_data(0);
+ }
+ display_data_end();
+ }
+}
#include "usb.h"
#include "app.h"
+#include <string.h>
+
/* USER CODE END Includes */
/* Private variables ---------------------------------------------------------*/
/* USER CODE END PFP */
/* USER CODE BEGIN 0 */
+byte rx_display[8];
+volatile byte rx_display_ready;
/* USER CODE END 0 */
LL_TIM_EnableIT_UPDATE(TIM4);
LL_TIM_GenerateEvent_UPDATE(TIM4);
+ {
+ byte buf[5] = { 0xff, 0xff, 10, 0xff, 0xff };
+ display_buffer(buf);
+ }
+
/* USER CODE END 2 */
/* Infinite loop */
/* USER CODE BEGIN WHILE */
- int cnt = 0;
while (1)
{
- debug_printf("Counter = %d\n", cnt);
- display_counter(cnt);
- LL_mDelay(1000);
- cnt++;
+ __disable_irq();
+ if (rx_display_ready)
+ {
+ byte rx[8];
+ rx_display_ready = 0;
+ memcpy(rx, rx_display, 8);
+ __enable_irq();
+ display_buffer(rx);
+ }
+ else
+ __enable_irq();
+
+ // debug_printf("Counter = %d\n", cnt);
+ // display_counter(cnt);
+
+ 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;
+
+ __WFI();
/* USER CODE END WHILE */
/* USER CODE BEGIN TIM4_IRQn 0 */
if (LL_TIM_IsActiveFlag_UPDATE(TIM4))
{
- 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;
+ // FIXME
LL_TIM_ClearFlag_UPDATE(TIM4);
}
#include "util.h"
#include "usb.h"
+#include "app.h"
+
+#include <string.h>
/*** Descriptors ***/
{
// usb_tx_buf[0]++;
// usb_ep_send(usb, 0x82, usb_tx_buf, 33);
+
+ u32 len = usb_ep_received_size(usb, 0x01);
+ if (len >= 8)
+ {
+ memcpy(rx_display, usb_rx_buf, 8);
+ rx_display_ready = 1;
+ }
+
usb_ep_receive(usb, 0x01, usb_rx_buf, 64);
}
}
#include <stdio.h>
#include <stdlib.h>
+#include <unistd.h>
+#include <time.h>
#include <libusb-1.0/libusb.h>
struct libusb_context *usb_ctxt;
for (;;)
{
- unsigned char req[64] = { 1, 2, 3, 4 };
+ time_t t = time(NULL);
+ struct tm *tm = localtime(&t);
+
+ unsigned char req[8] = {
+ tm->tm_hour / 10,
+ tm->tm_hour % 10,
+ (tm->tm_sec % 2 ? 10 : 0xff),
+ tm->tm_min / 10,
+ tm->tm_min % 10,
+ };
int transferred;
- if (err = libusb_bulk_transfer(devh, 0x01, req, 32, &transferred, 2000))
+ if (err = libusb_bulk_transfer(devh, 0x01, req, 8, &transferred, 2000))
{
fprintf(stderr, "Transfer failed: error %d\n", err);
exit(1);
}
printf("Transferred %d bytes\n", transferred);
-#if 1
+#if 0
unsigned char resp[1000];
int received;
if (err = libusb_bulk_transfer(devh, 0x82, resp, 1000, &received, 2000))
}
printf("Received %d bytes [%02x]\n", received, resp[0]);
#endif
+
+ sleep(1);
}
return 0;