一乐电子

一乐电子百科

 找回密码
 请使用微信账号登录和注册会员

QQ登录

只需一步,快速开始

快捷登录

手机号码,快捷登录

搜索
查看: 2655|回复: 13
收起左侧

熊那收的Btplug搞个盒子,不知道需不需要打散热孔?

[复制链接]
发表于 2013-4-3 15:02 | 显示全部楼层 |阅读模式
IMAG0705.jpg

IMAG0706.jpg

IMAG0707.jpg

IMAG0708.jpg

IMAG0709.jpg

IMAG0710.jpg

IMAG0711.jpg

IMAG0712.jpg

IMAG0713.jpg

IMAG0714.jpg

外壳设计来源于 NNzT 估计也是这个坛子里的。原设计使用榫卯结构,可以不用胶水,但要双面雕刻对装夹要求高!我自己改成用胶水粘。省事!

这是原设计。
QQ截图20130403150104.png

感谢 NNzT提供!

现在没有散热孔,不知道整体发热怎么样。
客官来玩啊。
发表于 2013-4-3 15:07 | 显示全部楼层
这东西没抢到。。。。。
发表于 2013-4-3 15:10 | 显示全部楼层
呵呵,鼻涕擦~
发表于 2013-4-3 15:19 | 显示全部楼层
我还以为你用btplug做了cnc的上位机呢
手工倒个角吧
发表于 2013-4-3 16:18 | 显示全部楼层
口水你的CNC控制器,我自己的机器准备装机了,兄弟可否分享资料仿照一个呢?
发表于 2013-4-3 18:29 | 显示全部楼层
呵呵,我也在这坛子里混,今早起床看到你半夜发的消息了,恭喜你的盒子完工,我的好久都没动了,我是自己开店做买卖的,过完年好忙,一直没时间弄它,前两天测试了下GPIO,可以驱动1602LCD,我准备在盒子上加个LCD显示窗口,和关机按钮,还不知道什么年月能完工呢
 楼主| 发表于 2013-4-3 19:17 | 显示全部楼层
zzy9903 发表于 2013-4-3 18:29 static/image/common/back.gif
呵呵,我也在这坛子里混,今早起床看到你半夜发的消息了,恭喜你的盒子完工,我的好久都没动了,我是自己开 ...

我也是拖了好久,才找到的材料!
驱动1602的源代码我找到了,可是我怎么编译都不通过,后来就没搞了!
你是怎么做到的啊?
客官来玩啊。
发表于 2013-4-3 19:24 | 显示全部楼层
口水雕刻机
发表于 2013-4-3 19:49 | 显示全部楼层
72hour 发表于 2013-4-3 19:17 static/image/common/back.gif
我也是拖了好久,才找到的材料!
驱动1602的源代码我找到了,可是我怎么编译都不通过,后来就没搞了!
...

我的驱动1602还没做呢,现在只是在dos下测试GPIO端口成功,可以点灯了,但是dos下驱动1602也没啥意义,linux下编程我还不会呢,有空研究一下,路还很长啊

 楼主| 发表于 2013-4-3 20:30 | 显示全部楼层
zzy9903 发表于 2013-4-3 19:49 static/image/common/back.gif
我的驱动1602还没做呢,现在只是在dos下测试GPIO端口成功,可以点灯了,但是dos下驱动1602也没啥意义,li ...

# RT1602C BTPlug GPIO接脚
DB0 ~ DB7   =>   GPIO00 ~ GPIO07
RS => GPIO10
RW => GPIO11
E  => GPIO13
Vdd/背光电压+ => 接串口的Vcc输出
GND => GPIO GND



makefile
  1. DRIVER_VERSION := 1.0.0.000

  2. KDIR := /lib/modules/$$$$(shell uname -r)/build
  3. PWD := $$$$(shell pwd)
  4. OBJ := gpio1602

  5. obj-m := $$$$(OBJ).o

  6. EXTRA_CFLAGS := -DDRIVER_VERSION="v$$$$(DRIVER_VERSION)"

  7. all: clean compile

  8. compile:
  9. $$$$(MAKE) -C $$$$(KDIR) M=$$$$(PWD) modules

  10. load:
  11. su -c "insmod ./usbdpfp.ko"

  12. load_debug:
  13. @echo "try "tail -f /var/log/message" in another window as root...";
  14. su -c "insmod ./$$$$(OBJ).ko debug=1"

  15. unload:
  16. -su -c "rmmod -s $$$$(OBJ)"

  17. clean:
  18. make -C /lib/modules/$$$$(shell uname -r)/build M=$$$$(PWD) clean

  19. debug: unload clean compile load_debug
复制代码
gpio1602.c
  1. /*
  2. 2011-04-18. version 0.1

  3. TTY DRIVER TO CONNECT LCM 1602 VIA BTPLUG GPIO

  4. 本源码以MIT-LICENSE授权发布

  5. Copyright (c) 2011 Jia Huang, jia.huang@geneegroup.com

  6. Permission is hereby granted, free of charge, to any person obtaining
  7. a copy of this software and associated documentation files (the
  8. "Software"), to deal in the Software without restriction, including
  9. without limitation the rights to use, copy, modify, merge, publish,
  10. distribute, sublicense, and/or sell copies of the Software, and to
  11. permit persons to whom the Software is furnished to do so, subject to
  12. the following conditions:

  13. The above copyright notice and this permission notice shall be
  14. included in all copies or substantial portions of the Software.

  15. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  16. EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  17. MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  18. NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  19. LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  20. OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  21. WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

  22. */

  23. #define DRV_NAME "gpio1602"
  24. #define DEV_NAME "ttyG"

  25. #include <linux/console.h>
  26. #include <linux/delay.h>
  27. #include <linux/err.h>
  28. #include <linux/kernel.h>
  29. #include <linux/module.h>
  30. #include <linux/mutex.h>
  31. #include <linux/tty.h>
  32. #include <linux/tty_driver.h>
  33. #include <linux/tty_flip.h>
  34. #include <linux/io.h>

  35. #define BYTE unsigned char
  36. #define UINT unsigned int
  37. #define BOOL unsigned char

  38. #define TRUE 1
  39. #define FALSE 0

  40. #define FLAG_RS 0x01
  41. #define FLAG_RW 0x02
  42. #define FLAG_E 0x04

  43. #define DATA_BUSY 0x80

  44. #define DATA_CTL 0x98
  45. #define DATA 0x78

  46. #define FLAG_CTL 0x99
  47. #define FLAG 0x79

  48. #define CMD_SET_OPT 0x20
  49. #define CMD_OPT_8BITS 0x10
  50. #define CMD_OPT_2LINES 0x08
  51. #define CMD_OPT_F5x10 0x04

  52. #define CMD_SET_DISP 0x08
  53. #define CMD_DISP_ON 0x04
  54. #define CMD_DISP_CURSOR_ON 0x02
  55. #define CMD_DISP_CURSOR_BLINK 0x01

  56. #define CMD_CLEAR 0x01
  57. #define CMD_RESET_CURSOR 0x02
  58. #define CMD_SET_MODE 0x04
  59. #define CMD_MODE_SHIFT_RIGHT 0x02
  60. #define CMD_MODE_SHIFT_SCREEN 0x01

  61. #define CMD_SET_MOVE 0x10
  62. #define CMD_MOVE_CURSOR 0x00
  63. #define CMD_MOVE_SCREEN 0x08
  64. #define CMD_MOVE_RIGHT 0x04
  65. #define CMD_MOVE_LEFT 0x00

  66. //#define FLAG_LINE1 0x00 //第一行显示位置0~15 0x00~0x0F
  67. //#define FLAG_LINE1 0x40 //第二行显示位置0~15 0x41~0x4F
  68. #define CMD_LOCATE 0x80
  69. #define CMD_LOCATE_LINE2 0x40

  70. #define MAX_X 16
  71. #define MAX_Y 2

  72. #define OUT(x,y) outb(y, x)
  73. #define IN(x) inb(x)
  74. #define DELAY(x) udelay(x)


  75. /*
  76. GPIO与1602连接:
  77. DB0 = GPIO 00
  78. |
  79. DB7 = GPIO 07

  80. RS = GPIO 10;
  81. RW = GPIO 11;
  82. E = GPIO 12;
  83. */

  84. static char g1602_buffer[MAX_Y][MAX_X];

  85. static BYTE g1602_busy(void)
  86. {
  87. BYTE is_busy;

  88. // rs = 0; rw = 1; e = 1; 检测忙标志
  89. OUT(FLAG, FLAG_RW|FLAG_E);
  90. OUT(DATA_CTL, 0); // set all pins to input mode
  91. DELAY(5);

  92. is_busy = (IN(DATA) & DATA_BUSY);

  93. // e = 0;
  94. OUT(FLAG, FLAG_RW);

  95. OUT(DATA_CTL, 0xff); // set all pins to OUTPut mode

  96. return is_busy;
  97. }

  98. static void g1602_command(BYTE cmd, int usec)
  99. {
  100. while (g1602_busy()) DELAY(5);

  101. // rs = 0; rw = 0; e = 0;
  102. OUT(FLAG, 0);
  103. OUT(DATA, cmd);

  104. // e = 1;
  105. OUT(FLAG, FLAG_E);
  106. DELAY(5);

  107. // e = 0;
  108. OUT(FLAG, 0);

  109. DELAY(usec);
  110. }

  111. static int g1602_cur_x = 0, g1602_cur_y = 0;

  112. static void g1602_locate(int x, int y)
  113. {
  114. BYTE flag = 0;

  115. if (y > 0) flag |= CMD_LOCATE_LINE2;
  116. flag |= (x >= MAX_X ? MAX_X - 1 : x);

  117. g1602_command(CMD_LOCATE|flag, 50);
  118. }

  119. static void g1602_clear(void) {
  120. g1602_cur_x = 0;
  121. g1602_cur_y = 0;
  122. g1602_command(CMD_CLEAR, 2000);
  123. }

  124. static void g1602_reset_cursor(void) {
  125. g1602_cur_x = 0;
  126. g1602_cur_y = 0;
  127. g1602_command(CMD_RESET_CURSOR, 2000);
  128. }

  129. static void g1602_putc(BYTE ch)
  130. {
  131. while(g1602_busy()) DELAY(5);

  132. // rs = 1; rw = 0; e = 0;
  133. OUT(FLAG, FLAG_RS);
  134. DELAY(5);

  135. OUT(DATA, ch);

  136. // rs = 1; rw = 0; e = 1;
  137. OUT(FLAG, FLAG_RS|FLAG_E);
  138. DELAY(5);

  139. // rs = 1; rw = 0; e = 0;
  140. OUT(FLAG, FLAG_RS);
  141. }

  142. static void g1602_raw_write(const char *s, int slen)
  143. {
  144. g1602_command(CMD_SET_MODE|CMD_MODE_SHIFT_RIGHT, 50);
  145. while (slen--) {
  146. g1602_putc(*s);
  147. ++s;
  148. }
  149. }

  150. static void g1602_scrollup(void) {

  151. BYTE y=0;
  152. for (y=1; y<MAX_Y; y++) {
  153. memcpy(g1602_buffer[y-1], g1602_buffer[y], MAX_X);
  154. }

  155. memset(&g1602_buffer[MAX_Y-1], ' ', MAX_X);

  156. // 更新整个屏幕
  157. g1602_clear();
  158. for (y=0; y<MAX_Y-1; y++) {
  159. g1602_locate(0,0);
  160. g1602_raw_write(g1602_buffer[y], MAX_X);
  161. }
  162. }

  163. static void g1602_relocate(BOOL force) {
  164. BOOL altered = FALSE;

  165. if (g1602_cur_x == MAX_X) {
  166. g1602_cur_x = 0;
  167. g1602_cur_y ++;
  168. altered = TRUE;
  169. }

  170. if (g1602_cur_y == MAX_Y) {
  171. g1602_scrollup();
  172. g1602_cur_x = 0;
  173. g1602_cur_y = MAX_Y - 1;
  174. altered = TRUE;
  175. }

  176. if (altered || force) {
  177. g1602_locate(g1602_cur_x, g1602_cur_y);
  178. }
  179. }

  180. static void g1602_show_cursor(BOOL show) {
  181. if (show) {
  182. g1602_command(CMD_SET_DISP|CMD_DISP_ON|CMD_DISP_CURSOR_ON|CMD_DISP_CURSOR_BLINK, 50);
  183. }
  184. else {
  185. g1602_command(CMD_SET_DISP|CMD_DISP_ON, 50);
  186. }
  187. }

  188. typedef enum {PARSE_NORMAL, PARSE_ESC, PARSE_CSI, PARSE_SPEC} PARSE_STATUS;

  189. static void g1602_write(const char *s, int slen)
  190. {
  191. char ch;
  192. int i;
  193. static PARSE_STATUS status = PARSE_NORMAL;
  194. static int codes[2] = {0, 0};
  195. static int code_i = 0;

  196. for (i=0; i < slen; i++) {
  197. ch = s[i];
  198. switch (status) {
  199. case PARSE_SPEC:
  200. if (ch >= '0' && ch <= '9') {
  201. codes[code_i] = codes[code_i] * 10 + (ch - '0');
  202. }
  203. else switch (ch) {
  204. case ';':
  205. code_i++;
  206. codes[code_i] = 0;
  207. break;
  208. case 'l':
  209. if (codes[0] == 25) {
  210. g1602_show_cursor(TRUE);
  211. }
  212. status = PARSE_NORMAL;
  213. break;
  214. case 'h':
  215. if (codes[0] == 25) {
  216. g1602_show_cursor(FALSE);
  217. }
  218. status = PARSE_NORMAL;
  219. break;
  220. default:
  221. status = PARSE_NORMAL;
  222. }
  223. break;
  224. case PARSE_CSI:
  225. if (ch >= '0' && ch <= '9') {
  226. codes[code_i] = codes[code_i] * 10 + (ch - '0');
  227. }
  228. else switch (ch) {
  229. case ';': // sep
  230. code_i++;
  231. codes[code_i] = 0;
  232. break;
  233. case '?': //cursor ?
  234. code_i = 0;
  235. codes[0] = 0;
  236. status = PARSE_SPEC;
  237. break;
  238. case 'J': //clear screen
  239. g1602_clear();
  240. status = PARSE_NORMAL;
  241. break;
  242. case 'K': //clean to end
  243. g1602_relocate(FALSE);
  244. {
  245. int n = MAX_X - g1602_cur_x;
  246. while (n--) g1602_putc(' ');
  247. }
  248. g1602_relocate(TRUE);
  249. status = PARSE_NORMAL;
  250. break;
  251. case 'H': //locate to x:y *[x:yH
  252. g1602_cur_x=codes[0];
  253. g1602_cur_y=codes[1];
  254. g1602_relocate(TRUE);
  255. status = PARSE_NORMAL;
  256. break;
  257. default:
  258. status = PARSE_NORMAL;
  259. }
  260. break;
  261. case PARSE_ESC:
  262. switch (ch) {
  263. case '[':
  264. status = PARSE_CSI;
  265. code_i = 0;
  266. codes[0] = 0;
  267. break;
  268. case 27:
  269. break;
  270. default:
  271. status = PARSE_NORMAL;
  272. i--; // 更新状态重新处理该字符
  273. }
  274. break;
  275. default:
  276. if (ch >= ' ') { // 空格
  277. g1602_relocate(FALSE);
  278. g1602_buffer[g1602_cur_y][g1602_cur_x] = ch;
  279. g1602_putc(ch);
  280. g1602_cur_x++;
  281. }
  282. else switch(ch) {
  283. case '\e': // ESC
  284. status = PARSE_ESC;
  285. break;
  286. case '\n':
  287. g1602_cur_x = 0;
  288. g1602_cur_y ++;
  289. g1602_relocate(TRUE);
  290. break;
  291. /* default: skip */
  292. }
  293. }
  294. }
  295. }

  296. static void g1602_puts(const char *s) {
  297. g1602_write(s, strlen(s));
  298. }

  299. static void g1602_init(void)
  300. {

  301. memset(g1602_buffer, ' ', MAX_Y * MAX_X);

  302. /* set GPIO port0[7-0] as OUTPut mode */
  303. OUT(DATA_CTL, 0xff);
  304. /* set GPIO port1[2-0] as OUTPut mode */
  305. OUT(FLAG_CTL, FLAG_RS|FLAG_RW|FLAG_E);

  306. g1602_command(CMD_SET_OPT|CMD_OPT_8BITS|CMD_OPT_2LINES, 50);
  307. g1602_command(CMD_SET_DISP|CMD_DISP_ON, 50);
  308. g1602_command(CMD_SET_MODE|CMD_MODE_SHIFT_RIGHT, 50);

  309. g1602_clear();

  310. }

  311. #define pr_init(fmt, args...) ({ static const __initconst char __fmt[] = fmt; printk(__fmt, ## args); })

  312. static struct tty_driver *gpio_driver;
  313. static struct tty_struct * volatile gpio_tty;
  314. static unsigned long gpio_count;
  315. static DEFINE_MUTEX(gpio_tty_mutex);

  316. static int
  317. gpio_open(struct tty_struct *tty, struct file *filp)
  318. {
  319. mutex_lock(&gpio_tty_mutex);
  320. pr_debug("open %lu\n", gpio_count);
  321. ++gpio_count;
  322. gpio_tty = tty;
  323. mutex_unlock(&gpio_tty_mutex);
  324. return 0;
  325. }

  326. static void
  327. gpio_close(struct tty_struct *tty, struct file *filp)
  328. {
  329. mutex_lock(&gpio_tty_mutex);
  330. pr_debug("close %lu\n", gpio_count);
  331. if (--gpio_count == 0)
  332. gpio_tty = NULL;
  333. mutex_unlock(&gpio_tty_mutex);
  334. }

  335. #ifndef CONFIG_BFIN_JTAG_COMM_CONSOLE
  336. # define acquire_console_sem()
  337. # define release_console_sem()
  338. #endif
  339. static int gpio_write(struct tty_struct *tty, const unsigned char *buf, int count)
  340. {
  341. acquire_console_sem();
  342. g1602_write(buf, count);
  343. release_console_sem();
  344. return count;
  345. }

  346. static void gpio_flush_chars(struct tty_struct *tty)
  347. {
  348. }

  349. static int gpio_write_room(struct tty_struct *tty)
  350. {
  351. if (tty->stopped)
  352. return 0;
  353. return 32768;
  354. }

  355. static int gpio_chars_in_buffer(struct tty_struct *tty)
  356. {
  357. return 0;
  358. }

  359. static struct tty_operations gpio_ops = {
  360. .open = gpio_open,
  361. .close = gpio_close,
  362. .write = gpio_write,
  363. /*.put_char = gpio_put_char,*/
  364. .flush_chars = gpio_flush_chars,
  365. .write_room = gpio_write_room,
  366. .chars_in_buffer = gpio_chars_in_buffer,
  367. /*.wait_until_sent = gpio_wait_until_sent,*/
  368. };

  369. static int __init gpio_init(void)
  370. {
  371. int ret;

  372. ret = -ENOMEM;

  373. gpio_driver = alloc_tty_driver(1);
  374. if (!gpio_driver)
  375. goto err;

  376. gpio_driver->owner = THIS_MODULE;
  377. gpio_driver->driver_name = DRV_NAME;
  378. gpio_driver->name = DEV_NAME;
  379. gpio_driver->type = TTY_DRIVER_TYPE_SERIAL;
  380. gpio_driver->subtype = SERIAL_TYPE_NORMAL;
  381. gpio_driver->init_termios = tty_std_termios;
  382. tty_set_operations(gpio_driver, &gpio_ops);

  383. ret = tty_register_driver(gpio_driver);
  384. if (ret)
  385. goto err;

  386. g1602_init();

  387. pr_init(KERN_INFO DRV_NAME ": initialized\n");

  388. return 0;

  389. err:
  390. put_tty_driver(gpio_driver);
  391. return ret;
  392. }

  393. static void __exit gpio_exit(void)
  394. {
  395. tty_unregister_driver(gpio_driver);
  396. put_tty_driver(gpio_driver);
  397. }

  398. static void gpio_console_write(struct console *co, const char *buf, unsigned count)
  399. {
  400. g1602_write(buf, count);
  401. }

  402. static struct tty_driver *gpio_console_device(struct console *co, int *index)
  403. {
  404. *index = co->index;
  405. return gpio_driver;
  406. }

  407. static struct console gpio_console = {
  408. .name = DEV_NAME,
  409. .write = gpio_console_write,
  410. .device = gpio_console_device,
  411. .flags = CON_ANYTIME | CON_PRINTBUFFER,
  412. .index = -1,
  413. };

  414. static int __init gpio_console_init(void)
  415. {
  416. register_console(&gpio_console);
  417. return 0;
  418. }

  419. MODULE_AUTHOR("Jia Huang <jia.huang@geneegroup.com>");
  420. MODULE_DESCRIPTION("TTY over GPIO for LCM1602");
  421. MODULE_LICENSE("MIT");

  422. module_init(gpio_init);
  423. module_exit(gpio_exit);
  424. console_initcall(gpio_console_init);
复制代码
现成的代码,但是在debian6现有能用的内核上没编译通过。

客官来玩啊。

本版积分规则

QQ|一淘宝店|手机版|商店|电子DIY套件|一乐电子 ( 粤ICP备09076165号 ) 公安备案粤公网安备 44522102000183号

GMT+8, 2024-4-20 05:34 , Processed in 0.064088 second(s), 37 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表