Advertisement
Guest User

Untitled

a guest
Mar 20th, 2019
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.96 KB | None | 0 0
  1. /*****************************************************************//**
  2. * @file main_sampler_test.cpp
  3. *
  4. * @brief Basic test of nexys4 ddr mmio cores
  5. *
  6. * @author p chu
  7. * @version v1.0: initial release
  8. *********************************************************************/
  9.  
  10. // #define _DEBUG
  11. #include "chu_init.h"
  12. #include "gpio_cores.h"
  13. #include "xadc_core.h"
  14. #include "sseg_core.h"
  15. #include "spi_core.h"
  16. #include "i2c_core.h"
  17. #include "ps2_core.h"
  18. #include "ddfs_core.h"
  19. #include "adsr_core.h"
  20.  
  21. bool reset = false;
  22.  
  23. int getBtnPress(DebounceCore *dbc, GpoCore *gpc, GpiCore *gpi){
  24. while(!reset){
  25. reset = gpi->read(0);
  26. for(int i = 0; i < 5; i++){
  27. int p = dbc->read_db(i);
  28. if(p == 1){
  29. gpc->write(1,i);
  30. return i;
  31. }else{
  32. gpc->write(0,i);
  33. }
  34. }
  35. }
  36. return -1;
  37. }
  38.  
  39. void ssegShow(SsegCore *sseg_p, int in_val, int dots[4]) {
  40. int d[4] = {(in_val&0xf),(in_val&0xff)>>0x4,(in_val&0xfff)>>0x8,(in_val&0xffff)>>0xC};
  41. for(int i = 0; i < 4; i++){
  42. uint8_t k = sseg_p->h2s(d[i]);
  43. sseg_p->write_1ptn(k, i);
  44. sseg_p->set_dp(dots[i]);
  45. }
  46. }
  47.  
  48. void wait1s(TimerCore *tmr, int mult){
  49. tmr->sleep(mult);
  50. }
  51. void displayInc(SsegCore *sseg_p, TimerCore *tmr, int val, int dots[4]){
  52. ssegShow(sseg_p, val, dots);
  53. wait1s(tmr, 1000000);
  54. return;
  55. }
  56.  
  57. bool read(GpiCore *gpi){
  58. reset = gpi->read(0);
  59. if(gpi->read(0)){
  60. return true;
  61. }else{
  62. return false;
  63. }
  64. }
  65.  
  66. TimerCore tmr(get_slot_addr(BRIDGE_BASE,S0_SYS_TIMER));
  67. GpoCore led(get_slot_addr(BRIDGE_BASE, S2_LED));
  68. GpiCore sw(get_slot_addr(BRIDGE_BASE, S3_SW));
  69. XadcCore adc(get_slot_addr(BRIDGE_BASE, S5_XDAC));
  70. PwmCore pwm(get_slot_addr(BRIDGE_BASE, S6_PWM));
  71. DebounceCore btn(get_slot_addr(BRIDGE_BASE, S7_BTN));
  72. SsegCore sseg(get_slot_addr(BRIDGE_BASE, S8_SSEG));
  73. SpiCore spi(get_slot_addr(BRIDGE_BASE, S9_SPI));
  74. I2cCore adt7420(get_slot_addr(BRIDGE_BASE, S10_I2C));
  75. Ps2Core ps2(get_slot_addr(BRIDGE_BASE, S11_PS2));
  76. DdfsCore ddfs(get_slot_addr(BRIDGE_BASE, S12_DDFS));
  77. AdsrCore adsr(get_slot_addr(BRIDGE_BASE, S13_ADSR), &ddfs);
  78.  
  79. //0 = 1, 2 = 5, 3 = 10, 1 = 20, 4 = toggle
  80. int main() {
  81. int dots[4] = {0,0,0,0};
  82. ssegShow(&sseg,0x0000,dots);
  83. int tot = 0x0;
  84. int dir = 1;
  85. read(&sw);
  86. while(true){
  87.  
  88. int sel = getBtnPress(&btn,&led,&sw);
  89. if(read(&sw)){
  90. tot = 0x0;
  91. dir = 1;
  92. ssegShow(&sseg, 0x0, dots);
  93. }else{
  94. switch(sel){
  95. case 0:
  96. displayInc(&sseg,&tmr,0x1,dots);
  97. tot+=0x1*dir;
  98. ssegShow(&sseg, tot, dots);
  99. break;
  100. case 1:
  101. displayInc(&sseg,&tmr,0x14,dots);
  102. tot+=0x14*dir;
  103. ssegShow(&sseg, tot, dots);
  104. break;
  105. case 2:
  106. displayInc(&sseg,&tmr,0x5,dots);
  107. tot+=0x5*dir;
  108. ssegShow(&sseg, tot, dots);
  109. break;
  110. case 3:
  111. displayInc(&sseg,&tmr,0xA,dots);
  112. tot+=0xA*dir;
  113. ssegShow(&sseg, tot, dots);
  114. break;
  115. case 4:
  116.  
  117. if(dir == 1){
  118. dir = -1;
  119. }else{
  120. dir = 1;
  121. }
  122. wait1s(&tmr, 1000000);
  123. break;
  124. default:
  125. break;
  126.  
  127. }
  128. }
  129. }
  130.  
  131. } //main
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement