Advertisement
Double_G

100-as ocsipanel to STM32 discovery

Feb 8th, 2023
32
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.09 KB | Source Code | 0 0
  1. // reads CDJ-100S buttons
  2. void Keyboard_Read() {
  3. HAL_GPIO_WritePin(S1_GPIO_Port, S1_Pin, GPIO_PIN_SET);
  4. if(HAL_GPIO_ReadPin(KD0_GPIO_Port, KD0_Pin) == GPIO_PIN_SET) {
  5. if(!(button_flags & (1 << HOLD))) {
  6. button_flags ^= (1 << HOLD);
  7. if(usb_status == CONNECTED) {
  8. MIDI_DataTx(Hold_On, 4);
  9. }
  10. Display_DataTx(Hold_On, 4);
  11. }
  12. }
  13. else {
  14. if(button_flags & (1 << HOLD)) {
  15. button_flags ^= (1 << HOLD);
  16. if(usb_status == CONNECTED) {
  17. MIDI_DataTx(Hold_Off, 4);
  18. }
  19. Display_DataTx(Hold_Off, 4);
  20. }
  21. }
  22. if(HAL_GPIO_ReadPin(KD1_GPIO_Port, KD1_Pin) == GPIO_PIN_SET) {
  23. if(!(button_flags & (1 << TRACKBACK))) {
  24. button_flags ^= (1 << TRACKBACK);
  25. if(usb_status == CONNECTED) {
  26. MIDI_DataTx(TrackBack_On, 4);
  27. }
  28. Display_DataTx(TrackBack_On, 4);
  29. }
  30. }
  31. else {
  32. if(button_flags & (1 << TRACKBACK)) {
  33. button_flags ^= (1 << TRACKBACK);
  34. if(usb_status == CONNECTED) {
  35. MIDI_DataTx(TrackBack_Off, 4);
  36. }
  37. Display_DataTx(TrackBack_Off, 4);
  38. }
  39. }
  40. if(HAL_GPIO_ReadPin(KD2_GPIO_Port, KD2_Pin) == GPIO_PIN_SET) {
  41. if(!(button_flags & (1 << PLAY))) {
  42. button_flags ^= (1 << PLAY);
  43. if(usb_status == CONNECTED) {
  44. MIDI_DataTx(Play_On, 4);
  45. }
  46. Display_DataTx(Play_On, 4);
  47. }
  48. }
  49. else {
  50. if(button_flags & (1 << PLAY)) {
  51. button_flags ^= (1 << PLAY);
  52. if(usb_status == CONNECTED) {
  53. MIDI_DataTx(Play_Off, 4);
  54. }
  55. Display_DataTx(Play_Off, 4);
  56. }
  57. }
  58. HAL_GPIO_WritePin(S1_GPIO_Port, S1_Pin, GPIO_PIN_RESET);
  59. HAL_GPIO_WritePin(S2_GPIO_Port, S2_Pin, GPIO_PIN_SET);
  60. if(HAL_GPIO_ReadPin(KD0_GPIO_Port, KD0_Pin) == GPIO_PIN_SET) {
  61. if(!(button_flags & (1 << TIME))) {
  62. button_flags ^= (1 << TIME);
  63. if(usb_status == CONNECTED) {
  64. MIDI_DataTx(Time_On, 4);
  65. }
  66. Display_DataTx(Time_On, 4);
  67. }
  68. }
  69. else {
  70. if(button_flags & (1 << TIME)) {
  71. button_flags ^= (1 << TIME);
  72. if(usb_status == CONNECTED) {
  73. MIDI_DataTx(Time_Off, 4);
  74. }
  75. Display_DataTx(Time_Off, 4);
  76. }
  77. }
  78. if(HAL_GPIO_ReadPin(KD1_GPIO_Port, KD1_Pin) == GPIO_PIN_SET) {
  79. if(!(button_flags & (1 << TRACKFORWARD))) {
  80. button_flags ^= (1 << TRACKFORWARD);
  81. if(usb_status == CONNECTED) {
  82. MIDI_DataTx(TrackForward_On, 4);
  83. }
  84. Display_DataTx(TrackForward_On, 4);
  85. }
  86. }
  87. else {
  88. if(button_flags & (1 << TRACKFORWARD)) {
  89. button_flags ^= (1 << TRACKFORWARD);
  90. if(usb_status == CONNECTED) {
  91. MIDI_DataTx(TrackForward_Off, 4);
  92. }
  93. Display_DataTx(TrackForward_Off, 4);
  94. }
  95. }
  96. if(HAL_GPIO_ReadPin(KD2_GPIO_Port, KD2_Pin) == GPIO_PIN_SET) {
  97. if(!(button_flags & (1 << CUE))) {
  98. button_flags ^= (1 << CUE);
  99. if(usb_status == CONNECTED) {
  100. MIDI_DataTx(Cue_On, 4);
  101. }
  102. Display_DataTx(Cue_On, 4);
  103. }
  104. }
  105. else {
  106. if(button_flags & (1 << CUE)) {
  107. button_flags ^= (1 << CUE);
  108. if(usb_status == CONNECTED) {
  109. MIDI_DataTx(Cue_Off, 4);
  110. }
  111. Display_DataTx(Cue_Off, 4);
  112. }
  113. }
  114. HAL_GPIO_WritePin(S2_GPIO_Port, S2_Pin, GPIO_PIN_RESET);
  115. HAL_GPIO_WritePin(S3_GPIO_Port, S3_Pin, GPIO_PIN_SET);
  116. if(HAL_GPIO_ReadPin(KD0_GPIO_Port, KD0_Pin) == GPIO_PIN_SET) {
  117. if(!(button_flags & (1 << EJECT))) {
  118. button_flags ^= (1 << EJECT);
  119. if(usb_status == CONNECTED) {
  120. MIDI_DataTx(Eject_On, 4);
  121. }
  122. Display_DataTx(Eject_On, 4);
  123. }
  124. }
  125. else {
  126. if(button_flags & (1 << EJECT)) {
  127. button_flags ^= (1 << EJECT);
  128. if(usb_status == CONNECTED) {
  129. MIDI_DataTx(Eject_Off, 4);
  130. }
  131. Display_DataTx(Eject_Off, 4);
  132. }
  133. }
  134. if(HAL_GPIO_ReadPin(KD1_GPIO_Port, KD1_Pin) == GPIO_PIN_SET) {
  135. if(!(button_flags & (1 << JET))) {
  136. button_flags ^= (1 << JET);
  137. if(usb_status == CONNECTED) {
  138. MIDI_DataTx(Jet_On, 4);
  139. }
  140. Display_DataTx(Jet_On, 4);
  141. }
  142. }
  143. else {
  144. if(button_flags & (1 << JET)) {
  145. button_flags ^= (1 << JET);
  146. if(usb_status == CONNECTED) {
  147. MIDI_DataTx(Jet_Off, 4);
  148. }
  149. Display_DataTx(Jet_Off, 4);
  150. }
  151. }
  152. if(HAL_GPIO_ReadPin(KD2_GPIO_Port, KD2_Pin) == GPIO_PIN_SET) {
  153. if(!(button_flags & (1 << SCANBACK))) {
  154. button_flags ^= (1 << SCANBACK);
  155. if(usb_status == CONNECTED) {
  156. MIDI_DataTx(ScanBack_On, 4);
  157. }
  158. Display_DataTx(ScanBack_On, 4);
  159. }
  160. }
  161. else {
  162. if(button_flags & (1 << SCANBACK)) {
  163. button_flags ^= (1 << SCANBACK);
  164. if(usb_status == CONNECTED) {
  165. MIDI_DataTx(ScanBack_Off, 4);
  166. }
  167. Display_DataTx(ScanBack_Off, 4);
  168. }
  169. }
  170. HAL_GPIO_WritePin(S3_GPIO_Port, S3_Pin, GPIO_PIN_RESET);
  171. HAL_GPIO_WritePin(S4_GPIO_Port, S4_Pin, GPIO_PIN_SET);
  172. if(HAL_GPIO_ReadPin(KD0_GPIO_Port, KD0_Pin) == GPIO_PIN_SET) {
  173. if(!(button_flags & (1 << MASTERTEMPO))) {
  174. button_flags ^= (1 << MASTERTEMPO);
  175. if(usb_status == CONNECTED) {
  176. MIDI_DataTx(MasterTempo_On, 4);
  177. }
  178. Display_DataTx(MasterTempo_On, 4);
  179. }
  180. }
  181. else {
  182. if(button_flags & (1 << MASTERTEMPO)) {
  183. button_flags ^= (1 << MASTERTEMPO);
  184. if(usb_status == CONNECTED) {
  185. MIDI_DataTx(MasterTempo_Off, 4);
  186. }
  187. Display_DataTx(MasterTempo_Off, 4);
  188. }
  189. }
  190. if(HAL_GPIO_ReadPin(KD1_GPIO_Port, KD1_Pin) == GPIO_PIN_SET) {
  191. if(!(button_flags & (1 << ZIP))) {
  192. button_flags ^= (1 << ZIP);
  193. if(usb_status == CONNECTED) {
  194. MIDI_DataTx(Zip_On, 4);
  195. }
  196. Display_DataTx(Zip_On, 4);
  197. }
  198. }
  199. else {
  200. if(button_flags & (1 << ZIP)) {
  201. button_flags ^= (1 << ZIP);
  202. if(usb_status == CONNECTED) {
  203. MIDI_DataTx(Zip_Off, 4);
  204. }
  205. Display_DataTx(Zip_Off, 4);
  206. }
  207. }
  208. if(HAL_GPIO_ReadPin(KD2_GPIO_Port, KD2_Pin) == GPIO_PIN_SET) {
  209. if(!(button_flags & (1 << SCANFORWARD))) {
  210. button_flags ^= (1 << SCANFORWARD);
  211. if(usb_status == CONNECTED) {
  212. MIDI_DataTx(ScanForward_On, 4);
  213. }
  214. Display_DataTx(ScanForward_On, 4);
  215. }
  216. }
  217. else {
  218. if(button_flags & (1 << SCANFORWARD)) {
  219. button_flags ^= (1 << SCANFORWARD);
  220. if(usb_status == CONNECTED) {
  221. MIDI_DataTx(ScanForward_Off, 4);
  222. }
  223. Display_DataTx(ScanForward_Off, 4);
  224. }
  225. }
  226. HAL_GPIO_WritePin(S4_GPIO_Port, S4_Pin, GPIO_PIN_RESET);
  227. HAL_GPIO_WritePin(S5_GPIO_Port, S5_Pin, GPIO_PIN_SET);
  228. if(HAL_GPIO_ReadPin(KD0_GPIO_Port, KD0_Pin) == GPIO_PIN_SET) {
  229. if(!(button_flags & (1 << JOG))) {
  230. button_flags ^= (1 << JOG);
  231. if(usb_status == CONNECTED) {
  232. MIDI_DataTx(Jog_On, 4);
  233. }
  234. Display_DataTx(Jog_On, 4);
  235. }
  236. }
  237. else {
  238. if(button_flags & (1 << JOG)) {
  239. button_flags ^= (1 << JOG);
  240. if(usb_status == CONNECTED) {
  241. MIDI_DataTx(Jog_Off, 4);
  242. }
  243. Display_DataTx(Jog_Off, 4);
  244. }
  245. }
  246. if(HAL_GPIO_ReadPin(KD1_GPIO_Port, KD1_Pin) == GPIO_PIN_SET) {
  247. if(!(button_flags & (1 << WAH))) {
  248. button_flags ^= (1 << WAH);
  249. if(usb_status == CONNECTED) {
  250. MIDI_DataTx(Wah_On, 4);
  251. }
  252. Display_DataTx(Wah_On, 4);
  253. }
  254. }
  255. else {
  256. if(button_flags & (1 << WAH)) {
  257. button_flags ^= (1 << WAH);
  258. if(usb_status == CONNECTED) {
  259. MIDI_DataTx(Wah_Off, 4);
  260. }
  261. Display_DataTx(Wah_Off, 4);
  262. }
  263. }
  264. HAL_GPIO_WritePin(S5_GPIO_Port, S5_Pin, GPIO_PIN_RESET);
  265. }
  266. / transmit data to STM32F746DISCO board via SPI1
  267. void Display_DataTx(uint8_t *data, uint16_t length) {
  268. HAL_GPIO_WritePin(SPI1_NSS_GPIO_Port, SPI1_NSS_Pin, GPIO_PIN_RESET);
  269. HAL_SPI_Transmit(&hspi1, data, length, 0x1000);
  270. HAL_GPIO_WritePin(SPI1_NSS_GPIO_Port, SPI1_NSS_Pin, GPIO_PIN_SET);
  271. }
  272.  
  273. // receive data from STM32F746DISCO board via SPI1
  274. void Display_DataRx() {
  275. uint8_t dummy_data[4] = {0};
  276. HAL_GPIO_WritePin(SPI1_NSS_GPIO_Port, SPI1_NSS_Pin, GPIO_PIN_RESET);
  277. HAL_SPI_TransmitReceive(&hspi1, dummy_data, spi_rx_buffer, 4, 0x1000);
  278. HAL_GPIO_WritePin(SPI1_NSS_GPIO_Port, SPI1_NSS_Pin, GPIO_PIN_SET);
  279. if((spi_rx_buffer[1] & 0xF0) == 0x90) {
  280. if((spi_rx_buffer[2] & (1 << 0))) {
  281. HAL_GPIO_WritePin(PLAY_GPIO_Port, PLAY_Pin, GPIO_PIN_SET);
  282. }
  283. else {
  284. HAL_GPIO_WritePin(PLAY_GPIO_Port, PLAY_Pin, GPIO_PIN_RESET);
  285. }
  286. if((spi_rx_buffer[2] & (1 << 1))) {
  287. HAL_GPIO_WritePin(CUE_GPIO_Port, CUE_Pin, GPIO_PIN_SET);
  288. }
  289. else {
  290. HAL_GPIO_WritePin(CUE_GPIO_Port, CUE_Pin, GPIO_PIN_RESET);
  291. }
  292. if((spi_rx_buffer[2] & (1 << 2))) {
  293. HAL_GPIO_WritePin(DISC_GPIO_Port, DISC_Pin, GPIO_PIN_SET);
  294. }
  295. else {
  296. HAL_GPIO_WritePin(DISC_GPIO_Port, DISC_Pin, GPIO_PIN_RESET);
  297. }
  298. if((spi_rx_buffer[2] & (1 << 3))) {
  299. Display_DataTx(Pitch, 4);
  300. }
  301. }
  302. }
Tags: cdj100
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement