SEED CAN FORK
Fork of SEEED_CAN by
seeed_can_spi.h@1:ad71faa09868, 2013-11-06 (annotated)
- Committer:
- Just4pLeisure
- Date:
- Wed Nov 06 20:16:11 2013 +0000
- Revision:
- 1:ad71faa09868
- Parent:
- 0:f5d099885d3d
- Child:
- 2:fd026fcfde94
Beta release of a CAN-BUS library for Seeed Studios' CAN BUS Shield
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Just4pLeisure | 0:f5d099885d3d | 1 | /* seeed_can_spi.h |
Just4pLeisure | 0:f5d099885d3d | 2 | * Copyright (c) 2013 Sophie Dexter |
Just4pLeisure | 0:f5d099885d3d | 3 | * |
Just4pLeisure | 0:f5d099885d3d | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
Just4pLeisure | 0:f5d099885d3d | 5 | * you may not use this file except in compliance with the License. |
Just4pLeisure | 0:f5d099885d3d | 6 | * You may obtain a copy of the License at |
Just4pLeisure | 0:f5d099885d3d | 7 | * |
Just4pLeisure | 0:f5d099885d3d | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
Just4pLeisure | 0:f5d099885d3d | 9 | * |
Just4pLeisure | 0:f5d099885d3d | 10 | * Unless required by applicable law or agreed to in writing, software |
Just4pLeisure | 0:f5d099885d3d | 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
Just4pLeisure | 0:f5d099885d3d | 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
Just4pLeisure | 0:f5d099885d3d | 13 | * See the License for the specific language governing permissions and |
Just4pLeisure | 0:f5d099885d3d | 14 | * limitations under the License. |
Just4pLeisure | 0:f5d099885d3d | 15 | */ |
Just4pLeisure | 0:f5d099885d3d | 16 | #ifndef _SEEED_CAN_SPI_H_ |
Just4pLeisure | 0:f5d099885d3d | 17 | #define _SEEED_CAN_SPI_H_ |
Just4pLeisure | 0:f5d099885d3d | 18 | |
Just4pLeisure | 0:f5d099885d3d | 19 | #include "seeed_can_defs.h" |
Just4pLeisure | 0:f5d099885d3d | 20 | |
Just4pLeisure | 0:f5d099885d3d | 21 | #ifdef __cplusplus |
Just4pLeisure | 0:f5d099885d3d | 22 | extern "C" { |
Just4pLeisure | 0:f5d099885d3d | 23 | #endif |
Just4pLeisure | 0:f5d099885d3d | 24 | |
Just4pLeisure | 0:f5d099885d3d | 25 | /** CAN driver typedefs |
Just4pLeisure | 0:f5d099885d3d | 26 | */ |
Just4pLeisure | 1:ad71faa09868 | 27 | /// Type definition to hold a Seeed Studios CAN-BUS Shield connections and resources structure |
Just4pLeisure | 1:ad71faa09868 | 28 | struct Seeed_MCP_CAN_Shield { |
Just4pLeisure | 0:f5d099885d3d | 29 | SPI spi; |
Just4pLeisure | 0:f5d099885d3d | 30 | DigitalOut ncs; |
Just4pLeisure | 0:f5d099885d3d | 31 | InterruptIn irq; |
Just4pLeisure | 0:f5d099885d3d | 32 | Seeed_MCP_CAN_Shield(SPI _spi_, DigitalOut _ncs_, InterruptIn _irq_) : |
Just4pLeisure | 0:f5d099885d3d | 33 | spi(_spi_), |
Just4pLeisure | 0:f5d099885d3d | 34 | ncs(_ncs_), |
Just4pLeisure | 0:f5d099885d3d | 35 | irq(_irq_) |
Just4pLeisure | 0:f5d099885d3d | 36 | {} |
Just4pLeisure | 0:f5d099885d3d | 37 | }; |
Just4pLeisure | 0:f5d099885d3d | 38 | typedef struct Seeed_MCP_CAN_Shield can_t; |
Just4pLeisure | 0:f5d099885d3d | 39 | |
Just4pLeisure | 0:f5d099885d3d | 40 | /** mcp2515 spi instructions |
Just4pLeisure | 0:f5d099885d3d | 41 | */ |
Just4pLeisure | 0:f5d099885d3d | 42 | void mcpReset(can_t *obj); // reset the MCP2515 CAN controller chip |
Just4pLeisure | 0:f5d099885d3d | 43 | |
Just4pLeisure | 0:f5d099885d3d | 44 | uint8_t mcpRead(can_t *obj, // read from a single MCP2512 register |
Just4pLeisure | 0:f5d099885d3d | 45 | const uint8_t address); |
Just4pLeisure | 0:f5d099885d3d | 46 | void mcpReadMultiple(can_t *obj, // read multiple, sequential, registers into an array |
Just4pLeisure | 0:f5d099885d3d | 47 | const uint8_t address, |
Just4pLeisure | 0:f5d099885d3d | 48 | uint8_t values[], |
Just4pLeisure | 0:f5d099885d3d | 49 | const uint8_t n); |
Just4pLeisure | 0:f5d099885d3d | 50 | void mcpReadBuffer(can_t *obj, // read the specified receive buffer into an array |
Just4pLeisure | 0:f5d099885d3d | 51 | const uint8_t command, |
Just4pLeisure | 0:f5d099885d3d | 52 | uint8_t values[], |
Just4pLeisure | 0:f5d099885d3d | 53 | const uint8_t n); |
Just4pLeisure | 0:f5d099885d3d | 54 | void mcpWrite(can_t *obj, // write to a single MCP2512 register |
Just4pLeisure | 0:f5d099885d3d | 55 | const uint8_t address, |
Just4pLeisure | 0:f5d099885d3d | 56 | const uint8_t value); |
Just4pLeisure | 0:f5d099885d3d | 57 | void mcpWriteMultiple(can_t *obj, // write an array into consecutive MCP2515 registers |
Just4pLeisure | 0:f5d099885d3d | 58 | const uint8_t address, |
Just4pLeisure | 0:f5d099885d3d | 59 | const uint8_t values[], |
Just4pLeisure | 0:f5d099885d3d | 60 | const uint8_t n); |
Just4pLeisure | 0:f5d099885d3d | 61 | void mcpWriteBuffer(can_t *obj, // write an array into the specified transmit buffer |
Just4pLeisure | 0:f5d099885d3d | 62 | const uint8_t command, |
Just4pLeisure | 0:f5d099885d3d | 63 | uint8_t values[], |
Just4pLeisure | 0:f5d099885d3d | 64 | const uint8_t n); |
Just4pLeisure | 0:f5d099885d3d | 65 | void mcpBufferRTS(can_t *obj, const uint8_t command); // initiate transmission of the specified MCP2515 transmit buffer |
Just4pLeisure | 0:f5d099885d3d | 66 | uint8_t mcpStatus(can_t *obj); // read the MCP2515's status register |
Just4pLeisure | 0:f5d099885d3d | 67 | uint8_t mcpReceiveStatus(can_t *obj); // read mcp2515's receive status register |
Just4pLeisure | 0:f5d099885d3d | 68 | void mcpBitModify(can_t *obj, // modify bits of a register specified by a mask |
Just4pLeisure | 0:f5d099885d3d | 69 | const uint8_t address, |
Just4pLeisure | 0:f5d099885d3d | 70 | const uint8_t mask, |
Just4pLeisure | 0:f5d099885d3d | 71 | const uint8_t data); |
Just4pLeisure | 0:f5d099885d3d | 72 | |
Just4pLeisure | 0:f5d099885d3d | 73 | #ifdef __cplusplus |
Just4pLeisure | 0:f5d099885d3d | 74 | }; |
Just4pLeisure | 0:f5d099885d3d | 75 | #endif |
Just4pLeisure | 0:f5d099885d3d | 76 | |
Just4pLeisure | 0:f5d099885d3d | 77 | #endif // SEEED_CAN_SPI_H |