Part of Slepp's ProjectsPastebinTURLImagebinFilebin
Feedback -- English French German Japanese
Create Upload Newest Tools Donate
Sign In | Create Account

Something
Sunday, December 7th, 2008 at 5:43:28pm UTC 

  1. Index: bootloader/fm_i2c.c
  2. ===================================================================
  3. --- bootloader/fm_i2c.c (revision 0)
  4. +++ bootloader/fm_i2c.c (revision 0)
  5. @@ -0,0 +1,100 @@
  6. +#include "as3525.h"
  7. +#include "generic_i2c.h"
  8. +
  9. +
  10. +#define I2C_GPIO(x) GPIOB_PIN(x)
  11. +#define I2C_GPIO_DIR GPIOB_DIR
  12. +#define I2C_SCL_PIN 4
  13. +#define I2C_SDA_PIN 5
  14. +
  15. +static void fm_scl_hi(void)
  16. +{
  17. +    I2C_GPIO(I2C_SCL_PIN) = 1 << I2C_SCL_PIN;
  18. +}
  19. +
  20. +static void fm_scl_lo(void)
  21. +{
  22. +    I2C_GPIO(I2C_SCL_PIN) = 0;
  23. +}
  24. +
  25. +static void fm_sda_hi(void)
  26. +{
  27. +    I2C_GPIO(I2C_SDA_PIN) = 1 << I2C_SDA_PIN;
  28. +}
  29. +
  30. +static void fm_sda_lo(void)
  31. +{
  32. +    I2C_GPIO(I2C_SDA_PIN) = 0;
  33. +}
  34. +
  35. +static void fm_sda_input(void)
  36. +{
  37. +    I2C_GPIO_DIR &= ~(1 << I2C_SDA_PIN);
  38. +}
  39. +
  40. +static void fm_sda_output(void)
  41. +{
  42. +    I2C_GPIO_DIR |= 1 << I2C_SDA_PIN;
  43. +}
  44. +
  45. +static void fm_scl_input(void)
  46. +{
  47. +    I2C_GPIO_DIR &= ~(1 << I2C_SCL_PIN);
  48. +}
  49. +
  50. +static void fm_scl_output(void)
  51. +{
  52. +    I2C_GPIO_DIR |= 1 << I2C_SCL_PIN;
  53. +}
  54. +
  55. +static int fm_sda(void)
  56. +{
  57. +    return (I2C_GPIO(I2C_SDA_PIN) != 0);
  58. +}
  59. +
  60. +static int fm_scl(void)
  61. +{
  62. +    return (I2C_GPIO(I2C_SCL_PIN) != 0);
  63. +}
  64. +
  65. +static void fm_delay(void)
  66. +{
  67. +    volatile int i, j;
  68. +   
  69. +    j = 0;
  70. +    for (i = 0; i < 20; i++) {
  71. +        j++;
  72. +    }
  73. +}
  74. +
  75. +
  76. +static struct i2c_interface fm_i2c_interface = {
  77. +    .address = 0x10 << 1,
  78. +   
  79. +    .scl_hi = fm_scl_hi,
  80. +    .scl_lo = fm_scl_lo,
  81. +    .sda_hi = fm_sda_hi,
  82. +    .sda_lo = fm_sda_lo,
  83. +    .sda_input = fm_sda_input,
  84. +    .sda_output = fm_sda_output,
  85. +    .scl_input = fm_scl_input,
  86. +    .scl_output = fm_scl_output,
  87. +    .scl = fm_scl,
  88. +    .sda = fm_sda,
  89. +   
  90. +    .delay_hd_sta = fm_delay,
  91. +    .delay_hd_dat = fm_delay,
  92. +    .delay_su_dat = fm_delay,
  93. +    .delay_su_sto = fm_delay,
  94. +    .delay_su_sta = fm_delay,
  95. +    .delay_thigh = fm_delay
  96. +};
  97. +
  98. +void fm_i2c_init(void)
  99. +{
  100. +    i2c_add_node(&fm_i2c_interface);
  101. +   
  102. +    GPIOB_AFSEL &= ~(1 << I2C_SCL_PIN);
  103. +    GPIOB_AFSEL &= ~(1 << I2C_SDA_PIN);
  104. +}
  105. +
  106. Index: bootloader/SOURCES
  107. ===================================================================
  108. --- bootloader/SOURCES  (revision 19357)
  109. +++ bootloader/SOURCES  (working copy)
  110. @@ -47,4 +47,6 @@
  111.  #elif CONFIG_CPU==AS3525
  112.  sansa_as3525.c
  113.  show_logo.c
  114. +fm_i2c.c
  115. +../../firmware/drivers/generic_i2c.c
  116.  #endif
  117. Index: bootloader/sansa_as3525.c
  118. ===================================================================
  119. --- bootloader/sansa_as3525.c   (revision 19357)
  120. +++ bootloader/sansa_as3525.c   (working copy)
  121. @@ -25,6 +25,7 @@
  122.  #include <stdio.h>
  123.  #include <system.h>
  124.  #include <inttypes.h>
  125. +#include <string.h>
  126.  #include "config.h"
  127.  #include "lcd.h"
  128.  #include "backlight-target.h"
  129. @@ -35,6 +36,8 @@
  130.  #include "disk.h"
  131.  #include "panic.h"
  132.  
  133. +#include "generic_i2c.h"
  134. +
  135.  int show_logo(void);
  136.  void main(void)
  137.  {
  138. @@ -42,10 +45,23 @@
  139.      int buffer_size;
  140.      void(*kernel_entry)(void);
  141.      int ret;
  142. +   
  143. +    static unsigned short int buf[16];
  144. +    unsigned short *ptr;
  145. +    int i;
  146.  
  147.      system_init();
  148.      kernel_init();
  149.  
  150. +    verbose = true;
  151. +
  152. +    /* read i2c */
  153. +#if 1
  154. +    fm_i2c_init();
  155. +    memset(buf, 0, sizeof(buf));
  156. +    i2c_read_data(0x20, -1, (unsigned char *)buf, 32);
  157. +#endif
  158. +   
  159.      lcd_init();
  160.      show_logo();
  161.  
  162. @@ -61,7 +77,16 @@
  163.          lcd_clear_display();
  164.          verbose = true;
  165.      }
  166. +   
  167. +    /* show i2c */
  168. +    ptr = buf;
  169. +    for (i = 0; i < 4; i++) {
  170. +        printf("%X %04X %04X %04X %04X", (i * 4 + 0xA) % 16, ptr[0], ptr[1], ptr[2], ptr[3]);
  171. +        ptr += 4;
  172. +    }
  173.  
  174. +    while (1);  /* hang */
  175. +
  176.      enable_irq();
  177.  
  178.      ret = storage_init();
  179. Index: firmware/drivers/generic_i2c.c
  180. ===================================================================
  181. --- firmware/drivers/generic_i2c.c      (revision 19357)
  182. +++ firmware/drivers/generic_i2c.c      (working copy)
  183. @@ -31,23 +31,48 @@
  184.  
  185.  static void i2c_start(struct i2c_interface *iface)
  186.  {
  187. +#if 0
  188.      iface->sda_hi();
  189.      iface->scl_hi();
  190.      iface->sda_lo();
  191.      iface->delay_hd_sta();
  192.      iface->scl_lo();
  193. +#else
  194. +    iface->scl_output();
  195. +
  196. +    iface->sda_output();
  197. +    iface->sda_hi();
  198. +    iface->scl_hi();
  199. +    iface->delay_hd_sta();
  200. +    iface->scl_output();
  201. +    iface->sda_lo();
  202. +    iface->delay_hd_sta();
  203. +    iface->scl_lo();
  204. +    iface->delay_hd_sta();
  205. +#endif
  206.  }
  207.  
  208.  static void i2c_stop(struct i2c_interface *iface)
  209.  {
  210. +#if 0
  211.      iface->sda_lo();
  212.      iface->scl_hi();
  213.      iface->delay_su_sto();
  214.      iface->sda_hi();
  215. +#else
  216. +    iface->sda_output();
  217. +    iface->sda_lo();
  218. +    iface->delay_hd_sta();
  219. +    iface->scl_hi();
  220. +    iface->delay_su_sto();
  221. +    iface->sda_hi();
  222. +    iface->delay_hd_sta();
  223. +#endif
  224.  }
  225.  
  226.  static void i2c_ack(struct i2c_interface *iface, bool ack)
  227.  {
  228. +#if 0
  229.      iface->scl_lo();
  230.      if ( ack )
  231.          iface->sda_lo();
  232. @@ -58,12 +83,24 @@
  233.      iface->scl_hi();
  234.      iface->delay_thigh();
  235.      iface->scl_lo();
  236. +#else
  237. +    iface->sda_output();
  238. +    if (ack)
  239. +        iface->sda_lo();
  240. +    else
  241. +        iface->sda_hi();
  242. +    iface->delay_su_dat();
  243. +    iface->scl_hi();
  244. +    iface->delay_thigh();
  245. +    iface->scl_lo();
  246. +    iface->delay_hd_sta();
  247. +#endif
  248.  }
  249.  
  250.  static int i2c_getack(struct i2c_interface *iface)
  251.  {
  252.      int ret = 1;
  253. -
  254. +#if 0
  255.      iface->sda_input();
  256.      iface->delay_su_dat();
  257.      iface->scl_hi();
  258. @@ -76,6 +113,17 @@
  259.      iface->sda_hi();
  260.      iface->sda_output();
  261.      iface->delay_hd_dat();
  262. +#else
  263. +    iface->sda_input();
  264. +    iface->delay_su_dat();
  265. +    iface->scl_hi();
  266. +    iface->delay_hd_dat();
  267. +    if (iface->sda())
  268. +        ret = 0;
  269. +    iface->delay_hd_dat();
  270. +    iface->scl_lo();
  271. +    iface->delay_hd_dat();
  272. +#endif
  273.      return ret;
  274.  }
  275.  
  276. @@ -84,8 +132,14 @@
  277.      int i;
  278.      unsigned char byte = 0;
  279.      
  280. +#if 0
  281. +#else
  282. +    iface->sda_input();
  283. +#endif
  284. +
  285.      /* clock in each bit, MSB first */
  286.      for ( i=0x80; i; i>>=1 ) {
  287. +#if 0   
  288.          iface->sda_input();
  289.          iface->scl_hi();
  290.          iface->delay_thigh();
  291. @@ -94,6 +148,15 @@
  292.          iface->scl_lo();
  293.          iface->delay_hd_dat();
  294.          iface->sda_output();
  295. +#else
  296. +        iface->scl_hi();
  297. +        iface->delay_thigh();
  298. +        if (iface->sda())
  299. +            byte |= i;
  300. +        iface->delay_hd_dat();
  301. +        iface->scl_lo();
  302. +        iface->delay_hd_dat();
  303. +#endif
  304.      }
  305.      
  306.      i2c_ack(iface, ack);
  307. @@ -105,17 +168,22 @@
  308.  {
  309.     int i;
  310.  
  311. +#if 0
  312. +#else
  313. +    iface->sda_output();
  314. +#endif
  315. +
  316.     /* clock out each bit, MSB first */
  317.     for (i=0x80; i; i>>=1) {
  318. -       if (i & byte)
  319. -           iface->sda_hi();
  320. -       else
  321. -           iface->sda_lo();
  322. -       iface->delay_su_dat();
  323. -       iface->scl_hi();
  324. -       iface->delay_thigh();
  325. -       iface->scl_lo();
  326. -       iface->delay_hd_dat();
  327. +        if (i & byte)
  328. +            iface->sda_hi();
  329. +        else
  330. +            iface->sda_lo();
  331. +        iface->delay_su_dat();
  332. +        iface->scl_hi();
  333. +        iface->delay_thigh();
  334. +        iface->scl_lo();
  335. +        iface->delay_hd_dat();   
  336.     }
  337.  
  338.     iface->sda_hi();
  339. @@ -175,23 +243,27 @@
  340.          return -1;
  341.      
  342.      i2c_start(iface);
  343. -    i2c_outb(iface, iface->address & 0xfe);
  344. +    i2c_outb(iface, iface->address | 1);
  345.      if (i2c_getack(iface)) {
  346. +#if 0
  347.          i2c_outb(iface, address);
  348.          if (i2c_getack(iface)) {
  349.              i2c_start(iface);
  350.              i2c_outb(iface, iface->address | 1);
  351.              if (i2c_getack(iface)) {
  352. +#endif
  353.                  for(i = 0;i < count-1;i++)
  354.                      buf[i] = i2c_inb(iface, true);
  355.                  
  356.                  buf[i] = i2c_inb(iface, false);
  357. +#if 0
  358.              } else {
  359.                  ret = -3;
  360.              }
  361.          } else {
  362.              ret = -2;
  363.          }
  364. +#endif
  365.      } else {
  366.          ret = -1;
  367.      }
  368. @@ -203,4 +275,10 @@
  369.  void i2c_add_node(struct i2c_interface *iface)
  370.  {
  371.      i2c_if[i2c_num_ifs++] = iface;
  372. +   
  373. +    iface->scl_output();
  374. +    iface->scl_hi();
  375. +    iface->sda_input();
  376.  }
  377. +
  378. +

Update the Post

Either update this post and resubmit it with changes, or make a new post.

You may also comment on this post.

update paste below
details of the post (optional)

Note: Only the paste content is required, though the following information can be useful to others.

Save name / title?

(space separated, optional)



Please note that information posted here will expire by default in one month. If you do not want it to expire, please set the expiry time above. If it is set to expire, web search engines will not be allowed to index it prior to it expiring. Items that are not marked to expire will be indexable by search engines. Be careful with your passwords. All illegal activities will be reported and any information will be handed over to the authorities, so be good.

comments powered by Disqus
worth-right
worth-right
worth-right