Advertisement
Guest User

USB R0

a guest
Sep 18th, 2012
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Diff 6.94 KB | None | 0 0
  1. diff --git a/apps/debug_menu.c b/apps/debug_menu.c
  2. index aec0a9a..f62ea89 100644
  3. --- a/apps/debug_menu.c
  4. +++ b/apps/debug_menu.c
  5. @@ -1915,7 +1915,7 @@ static bool dbg_fm_radio(void)
  6.  #endif /* CONFIG_TUNER */
  7.  #endif /* !SIMULATOR */
  8.  
  9. -#if defined(HAVE_LCD_BITMAP) && !defined(APPLICATION)
  10. +#if defined(HAVE_LCD_BITMAP) && (!defined(APPLICATION) || defined(SAMSUNG_YPR0))
  11.  extern bool do_screendump_instead_of_usb;
  12.  
  13.  static bool dbg_screendump(void)
  14. @@ -2184,7 +2184,7 @@ static const struct {
  15.  #if (CONFIG_BATTERY_MEASURE != 0) && !defined(SIMULATOR)
  16.          { "View battery", view_battery },
  17.  #endif
  18. -#ifndef APPLICATION
  19. +#if (!defined(APPLICATION) || defined(SAMSUNG_YPR0))
  20.          { "Screendump", dbg_screendump },
  21.  #endif
  22.  #endif
  23. diff --git a/apps/main.c b/apps/main.c
  24. index 6b6566c..05df4ed 100644
  25. --- a/apps/main.c
  26. +++ b/apps/main.c
  27. @@ -421,6 +421,8 @@ static void init(void)
  28.      scrobbler_init();
  29.  
  30.      audio_init();
  31. +    
  32. +    usb_init();
  33.  
  34.  #if (CONFIG_CODEC == SWCODEC) && defined(HAVE_RECORDING)
  35.      pcm_rec_init();
  36. diff --git a/firmware/SOURCES b/firmware/SOURCES
  37. index f5e2c76..6231f10 100644
  38. --- a/firmware/SOURCES
  39. +++ b/firmware/SOURCES
  40. @@ -96,6 +96,7 @@ target/hosted/ypr0/audio-ypr0.c
  41.  #if CONFIG_TUNER
  42.  target/hosted/ypr0/radio-ypr0.c
  43.  #endif
  44. +target/hosted/ypr0/usb-ypr0.c
  45.  #endif
  46.  
  47.  /* Maemo specific files */
  48. diff --git a/firmware/export/config/samsungypr0.h b/firmware/export/config/samsungypr0.h
  49. index e97dabc..29e05a1 100644
  50. --- a/firmware/export/config/samsungypr0.h
  51. +++ b/firmware/export/config/samsungypr0.h
  52. @@ -12,11 +12,10 @@
  53.  
  54.  #define MODEL_NAME   "Samsung YP-R0"
  55.  
  56. -/* Indeed to check that */
  57. -/*TODO: R0 should charge battery automatically, no software stuff to manage that. Just to know about some as3543 registers, that should be set after loading samsung's afe.ko module
  58. - */
  59.  /*TODO: implement USB data transfer management -> see safe mode script and think a way to implemtent it in the code */
  60. -#define USB_NONE
  61. +//#define USB_NONE
  62. +//#define HAVE_USBSTACK
  63. +//#define USE_ROCKBOX_USB
  64.  
  65.  /* There is only USB charging */
  66.  //#define HAVE_USB_POWER
  67. diff --git a/firmware/screendump.c b/firmware/screendump.c
  68. index 0dfe79a..0e19d24 100644
  69. --- a/firmware/screendump.c
  70. +++ b/firmware/screendump.c
  71. @@ -28,6 +28,9 @@
  72.  #include "stdlib.h"
  73.  #include "string.h"
  74.  #include "system.h"
  75. +#ifdef SAMSUNG_YPR0
  76. +    #include "rbpaths.h"
  77. +#endif
  78.  
  79.  #ifdef HAVE_REMOTE_LCD
  80.  #include "lcd-remote.h"
  81. @@ -120,11 +123,20 @@ void screen_dump(void)
  82.  #endif
  83.  
  84.  #if CONFIG_RTC
  85. +#ifdef SAMSUNG_YPR0
  86. +    create_datetime_filename(filename, HOME_DIR, "dump ", ".bmp", false);
  87. +#else
  88.      create_datetime_filename(filename, "", "dump ", ".bmp", false);
  89. +#endif
  90. +#else
  91. +#ifdef SAMSUNG_YPR0
  92. +    create_numbered_filename(filename, HOME_DIR, "dump_", ".bmp", 4
  93. +                             IF_CNFN_NUM_(, NULL));
  94.  #else
  95.      create_numbered_filename(filename, "", "dump_", ".bmp", 4
  96.                               IF_CNFN_NUM_(, NULL));
  97.  #endif
  98. +#endif
  99.  
  100.      fd = creat(filename, 0666);
  101.      if (fd < 0)
  102. diff --git a/firmware/target/hosted/ypr0/usb-ypr0.c b/firmware/target/hosted/ypr0/usb-ypr0.c
  103. new file mode 100644
  104. index 0000000..0ee4756
  105. --- /dev/null
  106. +++ b/firmware/target/hosted/ypr0/usb-ypr0.c
  107. @@ -0,0 +1,68 @@
  108. +/***************************************************************************
  109. + *             __________               __   ___.
  110. + *   Open      \______   \ ____   ____ |  | _\_ |__   _______  ___
  111. + *   Source     |       _//  _ \_/ ___\|  |/ /| __ \ /  _ \  \/  /
  112. + *   Jukebox    |    |   (  <_> )  \___|    < | \_\ (  <_> > <  <
  113. + *   Firmware   |____|_  /\____/ \___  >__|_ \|___  /\____/__/\_ \
  114. + *                     \/            \/     \/    \/            \/
  115. + * $Id$
  116. + *
  117. + * Copyright (C) 2012 Lorenzo Miori
  118. + *
  119. + * This program is free software; you can redistribute it and/or
  120. + * modify it under the terms of the GNU General Public License
  121. + * as published by the Free Software Foundation; either version 2
  122. + * of the License, or (at your option) any later version.
  123. + *
  124. + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
  125. + * KIND, either express or implied.
  126. + *
  127. + ****************************************************************************/
  128. +#include "config.h"
  129. +#include "stdbool.h"
  130. +#include "system.h"
  131. +#include "kernel.h"
  132. +#include "usb.h"
  133. +#include "sc900776.h"
  134. +#include "unistd.h"
  135. +#include "fcntl.h"
  136. +#include "stdio.h"
  137. +#include "sys/ioctl.h"
  138. +#include "stdlib.h"
  139. +
  140. +//static bool usb_attached = false;
  141. +
  142. +void usb_init_device(void)
  143. +{
  144. +    /* Start usb detection... */
  145. +    usb_start_monitoring();
  146. +}
  147. +
  148. +int usb_detect(void)
  149. +{
  150. +    unsigned status = USB_EXTRACTED;
  151. +    /* Check if this register is set...DEVICE_1 */
  152. +    sMinivet_t rs = { .addr = 0xA, .value = 0 };
  153. +    int fd = open("/dev/minivet", O_RDONLY); //TODO: open a single instance that remains open until app shutdown
  154. +                                             // since that's also used to see if we are connected to a charger
  155. +    if (fd >= 0)
  156. +    {
  157. +        if (ioctl(fd, IOCTL_MINIVET_READ_BYTE, &rs) >= 0) {
  158. +            printf("%i", rs.value);
  159. +            status = (rs.value >> 2) ? USB_INSERTED : USB_EXTRACTED;
  160. +        }
  161. +        close(fd);
  162. +    }
  163. +    return status;
  164. +}
  165. +
  166. +void usb_enable(bool on)
  167. +{
  168. +    //TODO: of course that won't be so in the end...
  169. +    if (on) {
  170. +        system("./usb_on");
  171. +    }
  172. +    else {
  173. +        system("./usb_off");
  174. +    }
  175. +}
  176. diff --git a/firmware/usb.c b/firmware/usb.c
  177. index 6823851..a482002 100644
  178. --- a/firmware/usb.c
  179. +++ b/firmware/usb.c
  180. @@ -51,7 +51,8 @@
  181.       (defined(HAVE_USBSTACK) && defined(USE_ROCKBOX_USB) && CONFIG_USBOTG == USBOTG_S3C6400X) || \
  182.       defined(CPU_TCC77X) || defined(CPU_TCC780X) || \
  183.       (CONFIG_USBOTG == USBOTG_JZ4740) || \
  184. -     (defined(USE_ROCKBOX_USB) && CONFIG_USBOTG == USBOTG_AS3525)
  185. +     (defined(USE_ROCKBOX_USB) && CONFIG_USBOTG == USBOTG_AS3525) || \
  186. +     (defined(SAMSUNG_YPR0))
  187.  #define USB_FULL_INIT
  188.  #endif
  189.  
  190. @@ -322,15 +323,19 @@ static inline bool usb_configure_drivers(int for_state)
  191.  
  192.  static inline void usb_slave_mode(bool on)
  193.  {
  194. +#if (CONFIG_PLATFORM & PLATFORM_NATIVE)
  195.      int rc;
  196. +#endif
  197.  
  198.      if(on)
  199.      {
  200.          DEBUGF("Entering USB slave mode\n");
  201. +#if (CONFIG_PLATFORM & PLATFORM_NATIVE)
  202.          disk_unmount_all();
  203.          storage_soft_reset();
  204.          storage_init();
  205.          storage_enable(false);
  206. +#endif
  207.          usb_enable(true);
  208.          cpu_idle_mode(true);
  209.      }
  210. @@ -345,6 +350,7 @@ static inline void usb_slave_mode(bool on)
  211.  
  212.          usb_enable(false);
  213.  
  214. +#if (CONFIG_PLATFORM & PLATFORM_NATIVE)
  215.          rc = storage_init();
  216.          if(rc)
  217.              panicf("storage: %d",rc);
  218. @@ -353,6 +359,7 @@ static inline void usb_slave_mode(bool on)
  219.          rc = disk_mount_all();
  220.          if(rc <= 0) /* no partition */
  221.              panicf("mount: %d",rc);
  222. +#endif
  223.      }
  224.  }
  225.  #endif /* HAVE_USBSTACK */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement