2 4 8 16 32 64 128 256 512 1024 2048 4096
| 139 | const static unsigned char SPI_DIV_TABLE[] = {0b0000, 0b0001, 0b0100, 0b0010, 0b0011, 0b0101, 0b0110, 0b0111, 0b1000, 0b1001, 0b1010, 0b1011}; |
| 140 | // 2 4 8 16 32 64 128 256 512 1024 2048 4096 |
| 141 | static rt_err_t configure(struct rt_spi_device *device, |
| 142 | struct rt_spi_configuration *configuration) |
| 143 | { |
| 144 | |
| 145 | unsigned char cpol = 0; |
| 146 | unsigned char cpha = 0; |
| 147 | |
| 148 | RT_ASSERT(NULL != device); |
| 149 | RT_ASSERT(NULL != configuration); |
| 150 | |
| 151 | // baudrate |
| 152 | if (configuration->mode & RT_SPI_CPOL) // cpol |
| 153 | { |
| 154 | cpol = 1; |
| 155 | } |
| 156 | else |
| 157 | { |
| 158 | cpol = 0; |
| 159 | } |
| 160 | if (configuration->mode & RT_SPI_CPHA) // cpha |
| 161 | { |
| 162 | cpha = 1; |
| 163 | } |
| 164 | else |
| 165 | { |
| 166 | cpha = 0; |
| 167 | } |
| 168 | |
| 169 | float spi_max_speed = ((float)APB_MAX_SPEED) / (8.0 / (float)APB_FREQSCALE); |
| 170 | uint64_t div = (uint64_t)(spi_max_speed / (float)configuration->max_hz); |
| 171 | int ctr = 0; |
| 172 | while (div != 1 && ctr < 12) |
| 173 | { |
| 174 | ctr++; |
| 175 | div = div >> 1; |
| 176 | } |
| 177 | spi_init(SPI_DIV_TABLE[ctr], cpol, cpha); |
| 178 | |
| 179 | return RT_EOK; |
| 180 | } |
| 181 | |
| 182 | static rt_uint32_t xfer(struct rt_spi_device *device, struct rt_spi_message *message) |
| 183 | { |
nothing calls this directly
no test coverage detected