Skip to content

Commit

Permalink
XY2_100 protocol up and running
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolas-rabault committed Jan 19, 2024
1 parent faf3780 commit 61186c4
Show file tree
Hide file tree
Showing 5 changed files with 256 additions and 59 deletions.
24 changes: 0 additions & 24 deletions examples/projects/NUCLEO-L476RG/laser/lib/Galvo/_galvo.h

This file was deleted.

46 changes: 34 additions & 12 deletions examples/projects/NUCLEO-L476RG/laser/lib/Galvo/galvo.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,21 @@
* @version 0.0.0
******************************************************************************/
#include "galvo.h"
#include "_galvo.h"
#include "xy2-100.h"

/*******************************************************************************
* Definitions
******************************************************************************/
uint8_t buf[40] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10,
11, 12, 13, 14, 15, 16, 17, 18, 19, 20,
21, 22, 23, 24, 25, 26, 27, 28, 29, 30,
31, 32, 33, 34, 35, 36, 37, 38, 39, 40};
typedef struct
{
uint16_t x;
uint16_t y;
} __attribute__((packed)) pos_2d_t;

pos_2d_t stream_buf[512];
streaming_channel_t stream;
time_luos_t period;
control_t control;

/*******************************************************************************
* Variables
Expand All @@ -35,7 +40,13 @@ void Galvo_Init(void)

revision_t revision = {.major = 1, .minor = 0, .build = 0};
Luos_CreateService(Galvo_MsgHandler, STATE_TYPE, "galvo", revision);
Xy_Start(buf, 40);
stream = Streaming_CreateChannel(stream_buf, 41, 2 * sizeof(uint16_t));
period = TimeOD_TimeFrom_s(1.0 / 100.0); // Configure the trajectory samplerate at 100Hz
control.flux = STOP;

period = TimeOD_TimeFrom_s(1.0 / 40.0);
Streaming_AddAvailableSampleNB(&stream, 40);
Xy_Start(&stream, period);
}
/******************************************************************************
* @brief loop must be call in project loop
Expand All @@ -55,12 +66,23 @@ static void Galvo_MsgHandler(service_t *service, const msg_t *msg)
{
if (msg->header.cmd == GET_CMD)
{
// The galvo don't send anything
return;
}
}

uint32_t Galvo_GetData(uint8_t **data)
{
*data = buf;
return 40;
if (msg->header.cmd == CONTROL)
{
// Get the control value
control_t last_control = control;
ControlOD_ControlFromMsg(&control, msg);
if (control.flux == PLAY && last_control.flux != PLAY)
{
// Start the trajectory
Xy_Start(&stream, period);
}
else
{
// Stop the trajectory
Xy_Stop();
}
}
}
10 changes: 10 additions & 0 deletions examples/projects/NUCLEO-L476RG/laser/lib/Galvo/galvo_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,11 @@
#define GALVO_Y_PIN GPIO_PIN_3
#endif

// ENABLE Pinout
#ifndef GALVO_ENABLE_PIN
#define GALVO_ENABLE_PIN GPIO_PIN_4
#endif

// ********************* TIMER *********************
#ifndef GALVO_TIMER
#define GALVO_TIMER TIM6
Expand Down Expand Up @@ -84,4 +89,9 @@
#define GALVO_DMA_IRQHANDLER() DMA1_Channel3_IRQHandler()
#endif

// ********************* BUFFER *********************
#ifndef GALVO_BUFFER_SIZE
#define GALVO_BUFFER_SIZE 4000 // Buffer size need to be a multiple of 40
#endif

#endif /* _GALVO_HAL_CONFIG_H_ */
Loading

0 comments on commit 61186c4

Please sign in to comment.