//
// Created by enik on 02.06.22.
//

#ifndef USBCANV1_CAN_H
#define USBCANV1_CAN_H

//#include "libs.h"

#include <stdbool.h>

#include "stm32f1xx_hal.h"

typedef uint8_t u8_t; 	///< 8-bit unsigned
typedef int8_t i8_t;	///< 8-bit signed
typedef uint16_t u16_t; ///< 16-bit unsigned
typedef int16_t i16_t;	///< 16-bit signed
typedef uint32_t u32_t; ///< 32-bit unsigned
typedef int32_t i32_t;	///< 32-bit signed
typedef float fl_t;	///< float type

#define __USR_BKPT() __asm__ __volatile__("BKPT")


/**
 * @brief CAN Speed in KBit/s
 */
typedef enum CAN_SPEED {
    CAN_SPD_1000,
    CAN_SPD_800,
    CAN_SPD_500,
    CAN_SPD_250,
    CAN_SPD_125,
    CAN_SPD_100,
    CAN_SPD_50,
    CAN_SPD_20,
    CAN_SPD_10,
} CAN_SPEED;

void CAN_SetSpeed(CAN_SPEED spd, CAN_HandleTypeDef *can); //
void CAN_SetMode(bool is_silent, CAN_HandleTypeDef *can); //
void CAN_SetLoopback(bool is_loopback, CAN_HandleTypeDef *can); //
bool CAN_IsOpened(CAN_HandleTypeDef *can); //
bool CAN_IsSilent(CAN_HandleTypeDef *can); //
bool CAN_IsLoopback(CAN_HandleTypeDef *can); //

void CAN_SetFilterMode(bool id_only, CAN_HandleTypeDef *can); //
void CAN_SetFilterID(u8_t *filt_id, CAN_HandleTypeDef *can); //
void CAN_SetFilterMask(u8_t *filt_mask, CAN_HandleTypeDef *can); //

void CAN_Transmit(u32_t id, u8_t *data, u8_t len, CAN_HandleTypeDef *can); //
void CAN_TransmitExt(u32_t id, u8_t *data, u8_t len, CAN_HandleTypeDef *can); //
void CAN_TransmitRTR(u32_t id, u8_t len, CAN_HandleTypeDef *can); //
void CAN_TransmitExtRTR(u32_t id, u8_t len, CAN_HandleTypeDef *can); //

#endif //USBCANV1_CAN_H
