Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding the el2828 driver #117

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ add_library(jsd-lib STATIC
jsd_el3208.c
jsd_el2124.c
jsd_el2809.c
jsd_el2828.c
jsd_egd.c
jsd_el3356.c
jsd_jed0101.c
Expand Down
9 changes: 9 additions & 0 deletions src/jsd.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include "jsd/jsd_el1008.h"
#include "jsd/jsd_el2124.h"
#include "jsd/jsd_el2809.h"
#include "jsd/jsd_el2828.h"
#include "jsd/jsd_el3104.h"
#include "jsd/jsd_el3162.h"
#include "jsd/jsd_el3202.h"
Expand Down Expand Up @@ -373,6 +374,8 @@ const char* jsd_driver_type_to_string(jsd_driver_type_t driver_type) {
return "JSD_DRIVER_TYPE_EL2124";
case JSD_DRIVER_TYPE_EL2809:
return "JSD_DRIVER_TYPE_EL2809";
case JSD_DRIVER_TYPE_EL2828:
return "JSD_DRIVER_TYPE_EL2828";
case JSD_DRIVER_TYPE_EL3104:
return "JSD_DRIVER_TYPE_EL3104";
case JSD_DRIVER_TYPE_EL3162:
Expand Down Expand Up @@ -479,6 +482,9 @@ bool jsd_driver_is_compatible_with_product_code(jsd_driver_type_t driver_type,
case JSD_DRIVER_TYPE_EL2809:
is_compatible = jsd_el2809_product_code_is_compatible(product_code);
break;
case JSD_DRIVER_TYPE_EL2828:
is_compatible = jsd_el2828_product_code_is_compatible(product_code);
break;
case JSD_DRIVER_TYPE_EGD:
is_compatible = jsd_egd_product_code_is_compatible(product_code);
break;
Expand Down Expand Up @@ -549,6 +555,9 @@ bool jsd_init_single_device(jsd_t* self, uint16_t slave_id) {
case JSD_DRIVER_TYPE_EL2809:
return jsd_el2809_init(self, slave_id);
break;
case JSD_DRIVER_TYPE_EL2828:
return jsd_el2828_init(self, slave_id);
break;
case JSD_DRIVER_TYPE_EL2124:
return jsd_el2124_init(self, slave_id);
break;
Expand Down
84 changes: 84 additions & 0 deletions src/jsd_el2828.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
#include "jsd/jsd_el2828.h"

#include <assert.h>

#include "jsd/jsd_sdo.h"

/****************************************************
* Public functions
****************************************************/

/**
* @brief RxPDO struct used to set device command data in SOEM IOmap
*/
typedef struct __attribute__((__packed__)) {
uint8_t flags;
} jsd_el2828_rxpdo_t;

const jsd_el2828_state_t* jsd_el2828_get_state(jsd_t* self, uint16_t slave_id) {
assert(self);
assert(jsd_el2828_product_code_is_compatible(
self->ecx_context.slavelist[slave_id].eep_id));

return &self->slave_states[slave_id].el2828;
}

void jsd_el2828_process(jsd_t* self, uint16_t slave_id) {
assert(self);
assert(jsd_el2828_product_code_is_compatible(
self->ecx_context.slavelist[slave_id].eep_id));

jsd_el2828_rxpdo_t* rxpdo =
(jsd_el2828_rxpdo_t*)self->ecx_context.slavelist[slave_id].outputs;

int ch;
for (ch = 0; ch < JSD_EL2828_NUM_CHANNELS; ch++) {
uint8_t output = self->slave_states[slave_id].el2828.output[ch];

if (output > 0) {
rxpdo->flags |= 0x01 << ch;
} else {
rxpdo->flags &= ~(0x01 << ch);
}
}
}

void jsd_el2828_write_single_channel(jsd_t* self, uint16_t slave_id,
uint8_t channel, uint8_t output) {
assert(self);
assert(jsd_el2828_product_code_is_compatible(
self->ecx_context.slavelist[slave_id].eep_id));

self->slave_states[slave_id].el2828.output[channel] = output;
}

void jsd_el2828_write_all_channels(jsd_t* self, uint16_t slave_id,
uint8_t output[JSD_EL2828_NUM_CHANNELS]) {
int ch;
for (ch = 0; ch < JSD_EL2828_NUM_CHANNELS; ch++) {
jsd_el2828_write_single_channel(self, slave_id, ch, output[ch]);
}
}

/****************************************************
* Private functions
****************************************************/

bool jsd_el2828_init(jsd_t* self, uint16_t slave_id) {
assert(self);
assert(jsd_el2828_product_code_is_compatible(
self->ecx_context.slavelist[slave_id].eep_id));
assert(self->ecx_context.slavelist[slave_id].eep_man ==
JSD_BECKHOFF_VENDOR_ID);

jsd_slave_config_t* config = &self->slave_configs[slave_id];

// no PO2SO callback for 2828 devices, so set the success flag now
config->PO2SO_success = true;

return true;
}

bool jsd_el2828_product_code_is_compatible(uint32_t product_code) {
return product_code == JSD_EL2828_PRODUCT_CODE;
}
30 changes: 30 additions & 0 deletions src/jsd_el2828.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#ifndef JSD_EL2828_H
#define JSD_EL2828_H

#ifdef __cplusplus
extern "C" {
#endif

#include "jsd/jsd_el2828_pub.h"

/** @brief Initializes el2828
*
* @param self pointer JSD context
* @param slave_id index of device on EtherCAT bus
* @return true on success, false on failure
*/
bool jsd_el2828_init(jsd_t* self, uint16_t slave_id);

/**
* @brief Checks whether a product code is compatible with EL2828.
*
* @param product_code The product code to be checked
* @return True if the product code is compatible, false otherwise.
*/
bool jsd_el2828_product_code_is_compatible(uint32_t product_code);

#ifdef __cplusplus
}
#endif

#endif
56 changes: 56 additions & 0 deletions src/jsd_el2828_pub.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
#ifndef JSD_EL2828_PUB_H
#define JSD_EL2828_PUB_H

#ifdef __cplusplus
extern "C" {
#endif

#include "jsd/jsd_el2828_types.h"
#include "jsd/jsd_pub.h"

/**
* @brief Read the EL2828 State
*
* Note: this device does not actually provide PDO feedback on state,
* This function reads back the cmd sent to the EL2828 device
*
* @param self pointer to JSD context
* @param slave_id id of EL2828 device
* @return Pointer to EL2828 device state
*/
const jsd_el2828_state_t* jsd_el2828_get_state(jsd_t* self, uint16_t slave_id);

/**
* @brief process loop required for proper device function
*
* @param self pointer to JSD context
* @param slave_id id of EL2828 device
*/
void jsd_el2828_process(jsd_t* self, uint16_t slave_id);

/**
* @brief Sets a specified channel level
*
* @param self pointer to JSD context
* @param slave_id id of EL2828 device
* @param channel specified device channel to command
* @param output command level (0 or 1)
*/
void jsd_el2828_write_single_channel(jsd_t* self, uint16_t slave_id,
uint8_t channel, uint8_t output);

/**
* @brief Sets all channel levels
*
* @param self pointer to JSD context
* @param slave_id id of EL2828 device
* @param output command level (0 or 1)
*/
void jsd_el2828_write_all_channels(jsd_t* self, uint16_t slave_id,
uint8_t output[JSD_EL2828_NUM_CHANNELS]);

#ifdef __cplusplus
}
#endif

#endif
31 changes: 31 additions & 0 deletions src/jsd_el2828_types.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#ifndef JSD_EL2828_TYPES_H
#define JSD_EL2828_TYPES_H

#ifdef __cplusplus
extern "C" {
#endif

#include "jsd/jsd_common_device_types.h"

#define JSD_EL2828_PRODUCT_CODE (uint32_t)0x0B0C3052

#define JSD_EL2828_NUM_CHANNELS 8

/**
* @brief EL2828 State Data
*/
typedef struct {
uint8_t output[JSD_EL2828_NUM_CHANNELS]; ///< digital output level (0 or 1)
} jsd_el2828_state_t;

/**
* @brief EL2828 device configuration
*/
typedef struct {
} jsd_el2828_config_t;

#ifdef __cplusplus
}
#endif

#endif
4 changes: 4 additions & 0 deletions src/jsd_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ extern "C" {
#include "jsd/jsd_el1008_types.h"
#include "jsd/jsd_el2124_types.h"
#include "jsd/jsd_el2809_types.h"
#include "jsd/jsd_el2828_types.h"
#include "jsd/jsd_el3104_types.h"
#include "jsd/jsd_el3162_types.h"
#include "jsd/jsd_el3202_types.h"
Expand All @@ -35,6 +36,7 @@ typedef enum {
JSD_DRIVER_TYPE_EL1008,
JSD_DRIVER_TYPE_EL2124,
JSD_DRIVER_TYPE_EL2809,
JSD_DRIVER_TYPE_EL2828,
JSD_DRIVER_TYPE_EL3104,
JSD_DRIVER_TYPE_EL3162,
JSD_DRIVER_TYPE_EL3202,
Expand All @@ -60,6 +62,7 @@ typedef struct {
jsd_el3208_config_t el3208;
jsd_el2124_config_t el2124;
jsd_el2809_config_t el2809;
jsd_el2828_config_t el2828;
jsd_egd_config_t egd;
jsd_el3356_config_t el3356;
jsd_jed0101_config_t jed0101;
Expand All @@ -85,6 +88,7 @@ typedef struct {
jsd_el3208_state_t el3208;
jsd_el2124_state_t el2124;
jsd_el2809_state_t el2809;
jsd_el2828_state_t el2828;
jsd_egd_private_state_t egd;
jsd_el3356_state_t el3356;
jsd_jed0101_state_t jed0101;
Expand Down
Loading