spi.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2017, James Jackson
3  *
4  * All rights reserved.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions are met:
8  *
9  * * Redistributions of source code must retain the above copyright notice, this
10  * list of conditions and the following disclaimer.
11  *
12  * * Redistributions in binary form must reproduce the above copyright notice,
13  * this list of conditions and the following disclaimer in the documentation
14  * and/or other materials provided with the distribution.
15  *
16  * * Neither the name of the copyright holder nor the names of its
17  * contributors may be used to endorse or promote products derived from
18  * this software without specific prior written permission.
19  *
20  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
23  * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
24  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
26  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
27  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
28  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30  */
31 
32 #pragma once
33 
34 #include "revo_f4.h"
35 
36 #include "gpio.h"
37 
38 class SPI
39 {
40 
41 public:
42 
43  void init(const spi_hardware_struct_t *conf);
44  void set_divisor(uint16_t new_divisor);
45 
46  void enable(GPIO &cs);
47  void disable(GPIO &cs);
48 
49  bool transfer(uint8_t *out_data, uint32_t num_bytes, uint8_t *in_data, GPIO *cs = NULL, void (*cb)(void) = NULL);
50  bool write(const uint8_t *out_data, uint32_t num_bytes, GPIO *cs = NULL);
51  uint8_t transfer_byte(uint8_t data, GPIO *cs = NULL);
52 
53  void transfer_complete_cb();
54  inline bool is_busy()
55  {
56  return busy_;
57  }
58 
59 private:
60 
61  void perform_transfer();
62  uint8_t *in_buffer_ptr_;
63  const uint8_t *out_buffer_ptr_;
64  uint32_t num_bytes_;
65 
70 
72 
73  uint32_t errors_ = 0;
75  volatile bool busy_ = false;
76  void (*transfer_cb_)(void) = NULL;
77 };
void transfer_complete_cb()
Definition: spi.cpp:257
uint32_t num_bytes_
Definition: spi.h:64
GPIO sck_
Definition: spi.h:69
DMA Init structure definition.
Definition: stm32f4xx_dma.h:54
Definition: spi.h:38
void enable(GPIO &cs)
Definition: spi.cpp:150
const spi_hardware_struct_t * c_
Definition: spi.h:66
bool transfer(uint8_t *out_data, uint32_t num_bytes, uint8_t *in_data, GPIO *cs=NULL, void(*cb)(void)=NULL)
Definition: spi.cpp:207
void(* transfer_cb_)(void)
Definition: spi.h:76
bool write(const uint8_t *out_data, uint32_t num_bytes, GPIO *cs=NULL)
Definition: spi.cpp:191
const uint8_t * out_buffer_ptr_
Definition: spi.h:63
GPIO * cs_
Definition: spi.h:74
GPIO miso_
Definition: spi.h:68
bool is_busy()
Definition: spi.h:54
volatile bool busy_
Definition: spi.h:75
uint8_t transfer_byte(uint8_t data, GPIO *cs=NULL)
Definition: spi.cpp:160
GPIO mosi_
Definition: spi.h:67
void set_divisor(uint16_t new_divisor)
Definition: spi.cpp:109
uint8_t * in_buffer_ptr_
Definition: spi.h:62
Definition: gpio.h:37
DMA_InitTypeDef DMA_InitStructure_
Definition: spi.h:71
void cb(uint8_t byte)
Definition: ublox.cpp:15
void perform_transfer()
Definition: spi.cpp:222
void init(const spi_hardware_struct_t *conf)
Definition: spi.cpp:40
#define NULL
Definition: usbd_def.h:50
uint32_t errors_
Definition: spi.h:73
void disable(GPIO &cs)
Definition: spi.cpp:155


rosflight_firmware
Author(s): Daniel Koch , James Jackson
autogenerated on Wed Jul 3 2019 19:59:25