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

Stuff
Tuesday, September 8th, 2009 at 7:38:34pm UTC 

  1. Index: firmware/target/arm/as3525/sansa-e200v2/lcd-e200v2.c
  2. ===================================================================
  3. --- firmware/target/arm/as3525/sansa-e200v2/lcd-e200v2.c        (revision 22658)
  4. +++ firmware/target/arm/as3525/sansa-e200v2/lcd-e200v2.c        (working copy)
  5. @@ -39,6 +39,7 @@
  6.   * (see lcd_button_support()), but that must not happen while the lcd is
  7.   * updating so block lcd_button_support the during updates */
  8.  static volatile bool lcd_busy = false;
  9. +static volatile unsigned short int dbop_input = 0xFFFF;
  10.  
  11.  /* register defines */
  12.  #define R_START_OSC             0x00
  13. @@ -98,6 +99,8 @@
  14.  #define R_DISP_CONTROL_REV    0x0000
  15.  static unsigned short r_disp_control_rev = R_DISP_CONTROL_NORMAL;
  16.  
  17. +static unsigned short lcd_dbop_read(void);
  18. +
  19.  /* TODO: Implement this function */
  20.  static void lcd_delay(int x)
  21.  {
  22. @@ -502,9 +505,13 @@
  23.      if (!display_on)
  24.          return;
  25.  
  26. +    lcd_busy = true;
  27. +
  28. +    /* do a DBOP read before doing a possibly length LCD write */
  29. +    dbop_input = lcd_dbop_read();
  30. +
  31.      lcd_write_reg(R_ENTRY_MODE, r_entry_mode);
  32.  
  33. -    lcd_busy = true;
  34.      /* Set start position and window */
  35.      lcd_window(0, 0, LCD_WIDTH-1, LCD_HEIGHT-1);
  36.  
  37. @@ -544,8 +551,12 @@
  38.      if (y >= ymax)
  39.          return; /* nothing left to do */
  40.  
  41. +    lcd_busy = true;
  42. +   
  43. +    /* do a DBOP read before doing a possibly length LCD write */
  44. +    dbop_input = lcd_dbop_read();
  45. +
  46.      lcd_write_reg(R_ENTRY_MODE, r_entry_mode);
  47. -    lcd_busy = true;
  48.      lcd_window(x, y, xmax, ymax);
  49.      lcd_write_cmd(R_WRITE_DATA_2_GRAM);
  50.  
  51. @@ -561,21 +572,43 @@
  52.      lcd_busy = false;
  53.  } /* lcd_update_rect */
  54.  
  55. -/* writes one red pixel outside the visible area, needed for correct
  56. - * dbop reads */
  57. -bool lcd_button_support(void)
  58. +
  59. +static unsigned short lcd_dbop_read(void)
  60.  {
  61. -    fb_data data = (0xf<<12);
  62. +    unsigned int dbop_ctrl_old = DBOP_CTRL;
  63. +    unsigned int dbop_timpol23_old = DBOP_TIMPOL_23;
  64. +    unsigned int value;
  65.  
  66. -    if (lcd_busy)
  67. -        return false;
  68. +    /* make sure that the DBOP FIFO is empty */
  69. +    while ((DBOP_STAT & (1<<10)) == 0);
  70.  
  71. -    lcd_write_reg(R_ENTRY_MODE, r_entry_mode);
  72. -    /* Set start position and window */
  73. -    lcd_window(LCD_WIDTH+1, LCD_HEIGHT+1, LCD_WIDTH+2, LCD_HEIGHT+2);
  74. +    /* write DBOP_DOUT to pre-charge DBOP data lines with a high level */
  75. +    DBOP_TIMPOL_23 = 0xe167e167;    /* no strobe towards lcd */
  76. +    DBOP_CTRL = (1 << 16) |         /* enw=1 (enable write) */
  77. +                (1 << 12);          /* ow=1 (16-bit data width) */
  78. +    DBOP_DOUT = 0xFFFF;             /* all pins high */
  79. +    while ((DBOP_STAT & (1<<10)) == 0);
  80.  
  81. -    lcd_write_cmd(R_WRITE_DATA_2_GRAM);
  82. +    /* perform a DBOP read */
  83. +    DBOP_CTRL = (1 << 15) |         /* strd=1 (start read) */
  84. +                (1 << 12) |         /* ow=1 (16-bit data width) */
  85. +                (31 << 0);          /* rs_t=31 (read DBOP at end of cycle) */
  86. +    while ((DBOP_STAT & (1<<16)) == 0);
  87. +    value = DBOP_DIN;
  88.  
  89. -    lcd_write_single_data16(data);
  90. -    return true;
  91. +    /* restore previous values */
  92. +    DBOP_TIMPOL_23 = dbop_timpol23_old;
  93. +    DBOP_CTRL = dbop_ctrl_old;
  94. +
  95. +    return value;
  96.  }
  97. +
  98. +/* get the DBOP input value, either directly or cached if DBOP is busy */
  99. +unsigned short int lcd_dbop_input(void)
  100. +{
  101. +    if (!lcd_busy) {
  102. +        dbop_input = lcd_dbop_read();
  103. +    }
  104. +    return dbop_input;
  105. +}
  106. +
  107. Index: firmware/target/arm/as3525/kernel-as3525.c
  108. ===================================================================
  109. --- firmware/target/arm/as3525/kernel-as3525.c  (revision 22658)
  110. +++ firmware/target/arm/as3525/kernel-as3525.c  (working copy)
  111. @@ -24,40 +24,14 @@
  112.  #include "panic.h"
  113.  #include "timer.h"
  114.  
  115. -#ifdef HAVE_SCROLLWHEEL
  116. -/* let the timer interrupt twice as often for the scrollwheel polling */
  117. -#define KERNEL_TIMER_FREQ (TIMER_FREQ/2)
  118. -#else
  119.  #define KERNEL_TIMER_FREQ TIMER_FREQ
  120. -#endif
  121.  
  122. -#ifdef HAVE_SCROLLWHEEL
  123. -#include "button-target.h"
  124. -/* The scrollwheel is polled every 5 ms (the tick tasks only every 10) */
  125. -static int poll_scrollwheel = 0;
  126. -
  127.  void INT_TIMER2(void)
  128.  {
  129. -    if (!poll_scrollwheel)
  130. -        call_tick_tasks();      /* Run through the list of tick tasks
  131. -                                 * (that includes reading the scrollwheel) */
  132. -    else
  133. -    {
  134. -        if (!button_hold())
  135. -            button_read_dbop(); /* Read the scrollwheel */
  136. -    }
  137. -
  138. -    poll_scrollwheel ^= 1;
  139. -    TIMER2_INTCLR = 0;  /* clear interrupt */
  140. -}
  141. -#else
  142. -void INT_TIMER2(void)
  143. -{
  144.      call_tick_tasks();  /* Run through the list of tick tasks */
  145.  
  146.      TIMER2_INTCLR = 0;  /* clear interrupt */
  147.  }
  148. -#endif
  149.  
  150.  void tick_start(unsigned int interval_in_ms)
  151.  {
  152. Index: firmware/target/arm/as3525/button-e200v2-fuze.c
  153. ===================================================================
  154. --- firmware/target/arm/as3525/button-e200v2-fuze.c     (revision 22658)
  155. +++ firmware/target/arm/as3525/button-e200v2-fuze.c     (working copy)
  156. @@ -32,7 +32,6 @@
  157.  #define WHEEL_COUNTER_DIV       4
  158.  #define ACCEL_INCREMENT         2
  159.  #define ACCEL_SHIFT             2
  160. -#define BUTTON_DELAY            60
  161.  #endif
  162.  
  163.  #ifdef SANSA_E200V2
  164. @@ -41,12 +40,6 @@
  165.  #define WHEEL_COUNTER_DIV       2
  166.  #define ACCEL_INCREMENT         3
  167.  #define ACCEL_SHIFT             1
  168. -#define BUTTON_DELAY            20
  169. -
  170. -/* read_missed is true if buttons could not
  171. - * be read (see lcd_button_support) */
  172. -static bool read_missed              = false;
  173. -
  174.  #endif
  175.  
  176.  /* Buttons */
  177. @@ -57,19 +50,18 @@
  178.  static unsigned short _dbop_din    = BUTTON_NONE;
  179.  
  180.  /* in the lcd driver */
  181. -extern bool lcd_button_support(void);
  182. +extern unsigned short int lcd_dbop_input(void);
  183.  
  184.  void button_init_device(void)
  185.  {
  186. -    GPIOA_DIR |= (1<<1);       
  187. +    GPIOA_DIR |= (1<<1);
  188.      GPIOA_PIN(1) = (1<<1);
  189.  }
  190.  
  191.  #if !defined(BOOTLOADER) && defined(HAVE_SCROLLWHEEL)
  192. -static void scrollwheel(unsigned short dbop_din)
  193. +static void scrollwheel(unsigned int wheel_value)
  194.  {
  195.      /* current wheel values, parsed from dbop and the resulting button */
  196. -    unsigned        wheel_value     = 0;
  197.      unsigned        btn             = BUTTON_NONE;
  198.      /* old wheel values */
  199.      static unsigned old_wheel_value = 0;
  200. @@ -92,7 +84,7 @@
  201.      /* We only post every 4th action, as this matches better with the physical
  202.       * clicks of the wheel */
  203.      static int counter = 0;
  204. -    /* Read wheel
  205. +    /* Read wheel
  206.       * Bits 13 and 14 of DBOP_DIN change as follows:
  207.       * Clockwise rotation   00 -> 01 -> 11 -> 10 -> 00
  208.       * Counter-clockwise    00 -> 10 -> 11 -> 01 -> 00
  209. @@ -100,7 +92,7 @@
  210.      static const unsigned char wheel_tbl[2][4] =
  211.      {
  212.          { 2, 0, 3, 1 }, /* Clockwise rotation */
  213. -        { 1, 3, 0, 2 }, /* Counter-clockwise  */
  214. +        { 1, 3, 0, 2 }, /* Counter-clockwise  */
  215.      };
  216.  
  217.      if(hold_button)
  218. @@ -109,9 +101,6 @@
  219.          return;
  220.      }
  221.  
  222. -    wheel_value = dbop_din & (1<<13|1<<14);
  223. -    wheel_value >>= 13;
  224. -
  225.      if (old_wheel_value == wheel_tbl[0][wheel_value])
  226.          btn = BUTTON_SCROLL_FWD;
  227.      else if (old_wheel_value == wheel_tbl[1][wheel_value])
  228. @@ -139,7 +128,7 @@
  229.          accel += ACCEL_INCREMENT;
  230.  
  231.          /* the wheel is more reliable if we don't send every change,
  232. -         * every WHEEL_COUNTER_DIVth is basically one "physical click"
  233. +         * every WHEEL_COUNTER_DIVth is basically one "physical click"
  234.           * which should make up 1 item in lists */
  235.          if (++counter >= WHEEL_COUNTER_DIV && queue_empty(&button_queue))
  236.          {
  237. @@ -151,11 +140,7 @@
  238.              last_wheel_post = current_tick;
  239.          }
  240.      }
  241. -    if (accel > 0
  242. -#ifdef SANSA_E200V2
  243. -         && !read_missed /* decrement only if reading buttons was successful */
  244. -#endif         
  245. -        )
  246. +    if (accel > 0)
  247.          accel--;
  248.  
  249.      old_wheel_value = wheel_value;
  250. @@ -167,167 +152,26 @@
  251.      return hold_button;
  252.  }
  253.  
  254. -static void button_delay(void)
  255. -{
  256. -    int i = BUTTON_DELAY;
  257. -    while(i--) asm volatile ("nop\n");
  258. -}
  259. -
  260. -unsigned short button_read_dbop(void)
  261. -{
  262. -#ifdef SANSA_FUZE
  263. -    /* skip home and power reading if lcd_button_support was blocked,
  264. -     * since the dbop bit 15 is invalid then, and use the old value instead
  265. -     * -20 (arbitary value) indicates valid home&power button read
  266. -     * (fuze only) */
  267. -    int old_home_power = -20;
  268. -#endif
  269. -    if(!lcd_button_support())
  270. -    {
  271. -#if defined(SANSA_FUZE)
  272. -        old_home_power = (_dbop_din & (1<<15|1<<8));
  273. -#elif defined(SANSA_E200V2)
  274. -        read_missed = true;
  275. -#endif
  276. -    }
  277. -
  278. -#ifdef SANSA_E200V2
  279. -    if (!read_missed)   /* read buttons only if lcd_button_support was not blocked */
  280. -#endif
  281. -    {
  282. -        /* Set up dbop for input */
  283. -        DBOP_CTRL |= (1<<19);                /* Tri-state DBOP on read cycle */
  284. -        DBOP_CTRL &= ~(1<<16);               /* disable output (1:write enabled) */
  285. -        DBOP_TIMPOL_01 = 0xe167e167;         /* Set Timing & Polarity regs 0 & 1 */
  286. -        DBOP_TIMPOL_23 = 0xe167006e;         /* Set Timing & Polarity regs 2 & 3 */
  287. -
  288. -        button_delay();
  289. -        DBOP_CTRL |= (1<<15);                /* start read */
  290. -        while (!(DBOP_STAT & (1<<16)));      /* wait for valid data */
  291. -
  292. -        _dbop_din = DBOP_DIN;                /* Read dbop data*/
  293. -
  294. -        /* Reset dbop for output */
  295. -        DBOP_TIMPOL_01 = 0x6e167;            /* Set Timing & Polarity regs 0 & 1 */
  296. -        DBOP_TIMPOL_23 = 0xa167e06f;         /* Set Timing & Polarity regs 2 & 3 */
  297. -        DBOP_CTRL |= (1<<16);                /* Enable output (0:write disable)  */
  298. -        DBOP_CTRL &= ~(1<<19);               /* Tri-state when no active write */
  299. -    }
  300. -
  301. -#ifdef SANSA_FUZE
  302. -    /* write back old values if blocked */
  303. -    if (old_home_power != -20)
  304. -    {
  305. -        _dbop_din |= old_home_power & 1<<15;
  306. -        _dbop_din &= 0xfeff|(old_home_power & 1<<8);
  307. -    }
  308. -#endif
  309. -
  310. -#if defined(HAVE_SCROLLWHEEL) && !defined(BOOTLOADER)
  311. -    /* read wheel on bit 13 & 14, but sent to the button queue seperately */
  312. -        scrollwheel(_dbop_din);
  313. -#endif
  314. -
  315. -#ifdef SANSA_E200V2
  316. -    read_missed = false;
  317. -#endif
  318. -
  319. -    return _dbop_din;
  320. -}
  321. -
  322.  /* for the debug menu */
  323.  unsigned short button_dbop_data(void)
  324.  {
  325.      return _dbop_din;
  326.  }
  327.  
  328. -static int button_gpio(void)
  329. -{
  330. -    int btn = BUTTON_NONE;
  331. -    if(hold_button)
  332. -        return btn;
  333. -
  334. -    /* disable DBOP output while changing GPIO pins that share lines with it */
  335. -    DBOP_CTRL &= ~(1<<16);
  336. -    button_delay();
  337. -   
  338. -    /* set afsel, so that we can read our buttons */
  339. -    GPIOC_AFSEL &= ~(1<<2|1<<3|1<<4|1<<5|1<<6);
  340. -    /* set dir so we can read our buttons (but reset the C pins first) */
  341. -    GPIOB_DIR &= ~(1<<4);
  342. -    GPIOC_DIR |= (1<<2|1<<3|1<<4|1<<5|1<<6);
  343. -    GPIOC_PIN(2) = (1<<2);
  344. -    GPIOC_PIN(3) = (1<<3);
  345. -    GPIOC_PIN(4) = (1<<4);
  346. -    GPIOC_PIN(5) = (1<<5);
  347. -    GPIOC_PIN(6) = (1<<6);
  348. -
  349. -    GPIOC_DIR &= ~(1<<2|1<<3|1<<4|1<<5|1<<6);
  350. -
  351. -    /* small delay needed to read buttons correctly */
  352. -    button_delay();
  353. -
  354. -    /* direct GPIO connections */
  355. -    if (!GPIOC_PIN(3))
  356. -        btn |= BUTTON_LEFT;
  357. -    if (!GPIOC_PIN(2))
  358. -        btn |= BUTTON_UP;
  359. -    if (!GPIOC_PIN(6))
  360. -        btn |= BUTTON_DOWN;
  361. -    if (!GPIOC_PIN(5))
  362. -        btn |= BUTTON_RIGHT;
  363. -    if (!GPIOC_PIN(4))
  364. -        btn |= BUTTON_SELECT;
  365. -    /* return to settings needed for lcd */
  366. -    GPIOC_DIR |= (1<<2|1<<3|1<<4|1<<5|1<<6);
  367. -    GPIOC_AFSEL |= (1<<2|1<<3|1<<4|1<<5|1<<6);
  368. -   
  369. -    DBOP_CTRL |= (1<<16);               /* enable output again */
  370. -    return btn;
  371. -}
  372. -
  373.  /*
  374.   * Get button pressed from hardware
  375.   */
  376.  int button_read_device(void)
  377.  {
  378. -    int btn = BUTTON_NONE;
  379. -    unsigned short dbop = button_read_dbop();
  380.  #ifdef SANSA_FUZE
  381.      static unsigned power_counter = 0;
  382.  #endif
  383. -    /* hold button */
  384. -    if(dbop & (1<<12))
  385. -    {
  386. -#ifdef SANSA_FUZE
  387. -        power_counter = HZ;
  388. -#endif
  389. -        hold_button = true;
  390. -    }
  391. -    else
  392. -    {
  393. -        hold_button = false;
  394. -#ifdef SANSA_FUZE
  395. -    /* read power on bit 8, but not if hold button was just released, since
  396. -     * you basically always hit power due to the slider mechanism after releasing
  397. -     * (fuze only)
  398. -     * hold (wait 1 sec) */
  399. -        if (power_counter)
  400. -            power_counter--;
  401. -#endif
  402. -        if (dbop & (1<<8)
  403. -#ifdef SANSA_FUZE
  404. -            && !power_counter
  405. -#endif
  406. -            )
  407. -            btn |= BUTTON_POWER;
  408. -    /* read home on bit 15 */
  409. -        if (!(dbop & (1<<15)))
  410. -            btn |= DBOP_BIT15_BUTTON;
  411. +    int btn = BUTTON_NONE;
  412.  
  413. -        btn |= button_gpio();
  414. -    }
  415. +    _dbop_din = lcd_dbop_input();
  416.  
  417. +    /* hold button handling */
  418. +    hold_button = ((_dbop_din && (1<<12)) == 0);
  419.  #ifndef BOOTLOADER
  420.      /* light handling */
  421.      if (hold_button != hold_button_old)
  422. @@ -336,6 +180,45 @@
  423.          backlight_hold_changed(hold_button);
  424.      }
  425.  #endif /* BOOTLOADER */
  426. +    if (hold_button) {
  427. +#ifdef SANSA_FUZE
  428. +        power_counter = HZ;
  429. +#endif
  430. +        return 0;
  431. +    }
  432.  
  433. +    /* push button handling */
  434. +    if ((_dbop_din & (1 << 2)) == 0)
  435. +        btn |= BUTTON_UP;
  436. +    if ((_dbop_din & (1 << 3)) == 0)
  437. +        btn |= BUTTON_LEFT;
  438. +    if ((_dbop_din & (1 << 4)) == 0)
  439. +        btn |= BUTTON_SELECT;
  440. +    if ((_dbop_din & (1 << 5)) == 0)
  441. +        btn |= BUTTON_RIGHT;
  442. +    if ((_dbop_din & (1 << 6)) == 0)
  443. +        btn |= BUTTON_DOWN;
  444. +    if ((_dbop_din & (1 << 8)) == 0)
  445. +        btn |= BUTTON_POWER;
  446. +    if ((_dbop_din & (1 << 15)) == 0)
  447. +        btn |= DBOP_BIT15_BUTTON;
  448. +
  449. +#ifdef SANSA_FUZE
  450. +        /* read power on bit 8, but not if hold button was just released, since
  451. +         * you basically always hit power due to the slider mechanism after releasing
  452. +         * (fuze only)
  453. +         */
  454. +    if (power_counter > 0) {
  455. +        power_counter--;
  456. +        btn &= ~BUTTON_POWER;
  457. +    }
  458. +#endif
  459. +
  460. +#if defined(HAVE_SCROLLWHEEL) && !defined(BOOTLOADER)
  461. +    /* scroll wheel handling */
  462. +    scrollwheel((_dbop_din >> 13) & 3);
  463. +#endif
  464. +
  465.      return btn;
  466.  }
  467. +

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