| 237 | |
| 238 | |
| 239 | SPIDevice::SPIDevice(SPIBus &bus, SPIDesc &device_desc) |
| 240 | : _bus(bus) |
| 241 | , _desc(device_desc) |
| 242 | { |
| 243 | set_device_bus(_bus.bus); |
| 244 | set_device_address(_desc.subdev); |
| 245 | _speed = _desc.highspeed; |
| 246 | |
| 247 | if (_desc.cs_pin != SPI_CS_KERNEL) { |
| 248 | _cs = hal.gpio->channel(_desc.cs_pin); |
| 249 | if (!_cs) { |
| 250 | AP_HAL::panic("Unable to instantiate cs pin"); |
| 251 | } |
| 252 | |
| 253 | _cs->mode(HAL_GPIO_OUTPUT); |
| 254 | |
| 255 | // do not hold the SPI bus initially |
| 256 | _cs_release(); |
| 257 | } |
| 258 | } |
| 259 | |
| 260 | SPIDevice::~SPIDevice() |
| 261 | { |