upm  1.7.1
Sensor/Actuator repository for libmraa (v2.0.0)
mcp2515.h
1 /*
2  * Author: Jon Trulson <jtrulson@ics.com>
3  * Copyright (c) 2016 Intel Corporation.
4  *
5  * Permission is hereby granted, free of charge, to any person obtaining
6  * a copy of this software and associated documentation files (the
7  * "Software"), to deal in the Software without restriction, including
8  * without limitation the rights to use, copy, modify, merge, publish,
9  * distribute, sublicense, and/or sell copies of the Software, and to
10  * permit persons to whom the Software is furnished to do so, subject to
11  * the following conditions:
12  *
13  * The above copyright notice and this permission notice shall be
14  * included in all copies or substantial portions of the Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20  * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21  * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22  * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23  */
24 #pragma once
25 
26 #include <stdint.h>
27 #include <stdlib.h>
28 #include <stdio.h>
29 #include <upm.h>
30 
31 #include <mraa/i2c.h>
32 #include <mraa/spi.h>
33 #include <mraa/gpio.h>
34 
35 #include "mcp2515_regs.h"
36 
37 #ifdef __cplusplus
38 extern "C" {
39 #endif
40 
53  typedef struct _mcp2515_context {
54  mraa_spi_context spi;
55 
56  // CS pin, if we are using one
57  mraa_gpio_context gpio;
58 
59  // interrupt, if enabled
60  mraa_gpio_context intr;
61  } *mcp2515_context;
62 
72  mcp2515_context mcp2515_init(int bus, int cs_pin);
73 
79  void mcp2515_close(mcp2515_context dev);
80 
87  upm_result_t mcp2515_reset(const mcp2515_context dev);
88 
100  upm_result_t mcp2515_set_opmode(const mcp2515_context dev,
101  MCP2515_OPMODE_T opmode);
102 
114  upm_result_t mcp2515_set_speed(const mcp2515_context dev,
115  MCP2515_SPEED_T speed);
116 
137  upm_result_t mcp2515_load_tx_buffer(const mcp2515_context dev,
138  MCP2515_TX_BUFFER_T bufnum,
139  int id, bool ext, bool rtr,
140  uint8_t *payload, int len);
141 
152  upm_result_t mcp2515_transmit_buffer(const mcp2515_context dev,
153  MCP2515_TX_BUFFER_T bufnum,
154  bool wait);
155 
166  bool mcp2515_tx_buffer_is_free(const mcp2515_context dev,
167  MCP2515_TX_BUFFER_T bufnum);
168 
176  MCP2515_TX_BUFFER_T mcp2515_find_free_tx_buffer(const mcp2515_context dev);
177 
191  upm_result_t mcp2515_set_tx_buffer_priority(const mcp2515_context dev,
192  MCP2515_TX_BUFFER_T bufnum,
193  MCP2515_TXP_T priority);
194 
207  upm_result_t mcp2515_abort_tx(const mcp2515_context dev,
208  MCP2515_TX_BUFFER_T bufnum);
209 
225  upm_result_t mcp2515_set_rx_buffer_mode(const mcp2515_context dev,
226  MCP2515_RX_BUFFER_T bufnum,
227  MCP2515_RXMODE_T rxm);
228 
239  MCP2515_RXMSG_T mcp2515_rx_status_msgs(const mcp2515_context dev);
240 
251  MCP2515_MSGTYPE_T mcp2515_rx_status_msg_type(const mcp2515_context dev);
252 
262  MCP2515_FILTERMATCH_T mcp2515_rx_status_filtermatch(const mcp2515_context dev);
263 
278  upm_result_t mcp2515_get_rx_msg(const mcp2515_context dev,
279  MCP2515_RX_BUFFER_T bufnum,
280  MCP2515_MSG_T *msg);
281 
297  void mcp2515_print_msg(const mcp2515_context dev, MCP2515_MSG_T *msg);
298 
310  upm_result_t mcp2515_install_isr(const mcp2515_context dev, int pin,
311  void (*isr)(void *), void *arg);
312 
318  void mcp2515_uninstall_isr(const mcp2515_context dev);
319 
328  upm_result_t mcp2515_set_intr_enables(const mcp2515_context dev,
329  uint8_t enables);
330 
340  upm_result_t mcp2515_get_intr_flags(const mcp2515_context dev,
341  uint8_t *flags);
342 
353  upm_result_t mcp2515_set_intr_flags(const mcp2515_context dev,
354  uint8_t flags);
355 
366  upm_result_t mcp2515_clear_intr_flags(const mcp2515_context dev,
367  uint8_t flags);
368 
377  upm_result_t mcp2515_get_error_flags(const mcp2515_context dev,
378  uint8_t *flags);
379 
389  upm_result_t mcp2515_clear_error_flags(const mcp2515_context dev,
390  uint8_t flags);
391 
407  upm_result_t mcp2515_set_filter(const mcp2515_context dev,
408  MCP2515_RX_FILTER_T filter, bool ext,
409  int id);
410 
427  upm_result_t mcp2515_set_mask(const mcp2515_context dev,
428  MCP2515_RX_MASK_T mask, bool ext, int id);
429 
444  upm_result_t mcp2515_bus_read(const mcp2515_context dev, uint8_t cmd,
445  uint8_t *args, unsigned int arglen,
446  uint8_t *data, uint8_t len);
447 
460  upm_result_t mcp2515_bus_write(const mcp2515_context dev, uint8_t cmd,
461  uint8_t *data, uint8_t len);
462 
474  upm_result_t mcp2515_write_reg(const mcp2515_context dev, uint8_t reg,
475  uint8_t value);
476 
489  upm_result_t mcp2515_write_regs(const mcp2515_context dev, uint8_t reg,
490  uint8_t *buffer, int len);
491 
503  upm_result_t mcp2515_read_reg(const mcp2515_context dev, uint8_t reg,
504  uint8_t *value);
505 
520  upm_result_t mcp2515_bit_modify(const mcp2515_context dev, uint8_t addr,
521  uint8_t mask, uint8_t value);
522 
523 #ifdef __cplusplus
524 }
525 #endif
Definition: mcp2515.h:53
Definition: mcp2515_regs.h:92