Received: from PCH.mit.edu (18.7.21.50) by mail.efplus.com (192.168.0.8) with Microsoft SMTP Server (TLS) id 8.3.485.1; Thu, 30 Jul 2020 11:36:00 -0700 Received: from PCH.MIT.EDU (localhost.localdomain [127.0.0.1]) by PCH.mit.edu (8.14.7/8.12.8) with ESMTP id 06UIQ43C029881; Thu, 30 Jul 2020 14:26:22 -0400 Received: from outgoing-exchange-3.mit.edu (OUTGOING-EXCHANGE-3.MIT.EDU [18.9.28.13]) by PCH.mit.edu (8.14.7/8.12.8) with ESMTP id 06UIQ25L029878 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Thu, 30 Jul 2020 14:26:02 -0400 Received: from w92exedge3.exchange.mit.edu (W92EXEDGE3.EXCHANGE.MIT.EDU [18.7.73.15]) by outgoing-exchange-3.mit.edu (8.14.7/8.12.4) with ESMTP id 06UIS3MI029502 for ; Thu, 30 Jul 2020 14:28:04 -0400 Received: from w92expo29.exchange.mit.edu (18.7.74.41) by w92exedge3.exchange.mit.edu (18.7.73.15) with Microsoft SMTP Server (TLS) id 15.0.1293.2; Thu, 30 Jul 2020 14:25:38 -0400 Received: from oc11exhyb5.exchange.mit.edu (18.9.1.110) by w92expo29.exchange.mit.edu (18.7.74.41) with Microsoft SMTP Server (TLS) id 15.0.1365.1; Thu, 30 Jul 2020 14:26:02 -0400 Received: from NAM12-MW2-obe.outbound.protection.outlook.com (104.47.66.41) by oc11exhyb5.exchange.mit.edu (18.9.1.110) with Microsoft SMTP Server (TLS) id 15.0.1395.4 via Frontend Transport; Thu, 30 Jul 2020 14:26:01 -0400 Received: from MWHPR10CA0018.namprd10.prod.outlook.com (2603:10b6:301::28) by CH2PR01MB5877.prod.exchangelabs.com (2603:10b6:610:42::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3216.26; Thu, 30 Jul 2020 18:25:58 +0000 Received: from CO1NAM03FT040.eop-NAM03.prod.protection.outlook.com (2603:10b6:301:0:cafe::64) by MWHPR10CA0018.outlook.office365.com (2603:10b6:301::28) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3239.16 via Frontend Transport; Thu, 30 Jul 2020 18:25:57 +0000 Received: from mail-yb1-f172.google.com (209.85.219.172) by CO1NAM03FT040.mail.protection.outlook.com (10.152.81.183) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3216.10 via Frontend Transport; Thu, 30 Jul 2020 18:25:57 +0000 Received: by mail-yb1-f172.google.com with SMTP id 2so14919424ybr.13 for ; Thu, 30 Jul 2020 11:25:57 -0700 (PDT) From: Manu Abraham To: Microcontroller discussion list - Public. Sender: "piclist-bounces@mit.edu" Date: Thu, 30 Jul 2020 11:25:43 -0700 Subject: Re: [PIC] Simple GCC question Thread-Topic: [PIC] Simple GCC question Thread-Index: AdZmoEZ27zTDaCxJTn69gp7Ig0B+vQ== Message-ID: References: List-Help: List-Subscribe: , List-Unsubscribe: , In-Reply-To: Reply-To: Microcontroller discussion list - Public. Accept-Language: en-US X-MS-Exchange-Organization-AuthAs: Anonymous X-MS-Exchange-Organization-AuthSource: TS500.efplus4.local X-MS-Has-Attach: X-Auto-Response-Suppress: All X-MS-Exchange-Organization-SenderIdResult: Pass X-MS-Exchange-Organization-PRD: mit.edu X-MS-TNEF-Correlator: received-spf: Pass (protection.outlook.com: domain of gmail.com designates 209.85.219.172 as permitted sender) receiver=protection.outlook.com; client-ip=209.85.219.172; helo=mail-yb1-f172.google.com; dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :content-transfer-encoding; bh=5KQBStt2oquUAtMiikFOi+yzTm53YhzZUeZTCx5hQgM=; b=vZqVR5dGfATjszC307ltFiqDFCC+gU4mSlKfP8qTtRBZOntrBnncfRrxZ9cwMXw6bv Z20eX4tWEL0gBPe5NRAe12MmStCIJHtIwFn2Gx2Bi7GRprA4HNoT+eBOe/nzUek6M2X2 vxPZW/wysaFNeimRkN8j4cludXIYm6IfriKDYWM+jPqFKo3sj6f7ykVgRSDtiM9Sv9mq T96c74Ld/C3TfL9Wpq0+9nnC9GA4+ygUfaO4NAXKySXBwK0NXG5aUmoQFQbZG1dNNj3C B7gyfvd4iIfkn6mXoGcG8EHOzoj4Trhpo9EWRthxM5QGSvRmeEU4GUElAJUwkfqjYb5v J0aw== authentication-results: spf=pass (sender IP is 209.85.219.172) smtp.mailfrom=gmail.com; mit.edu; dkim=pass (signature was verified) header.d=gmail.com; mit.edu; dmarc=pass action=none header.from=gmail.com; errors-to: piclist-bounces@mit.edu list-id: "Microcontroller discussion list - Public." list-post: x-beenthere: piclist@mit.edu x-mailman-version: 2.1.6 x-received: by 2002:a25:c60b:: with SMTP id k11mr270297ybf.482.1596133556120; Thu, 30 Jul 2020 11:25:56 -0700 (PDT) x-topics: [PIC] x-mime-autoconverted: from quoted-printable to 8bit by PCH.mit.edu id 06UIQ25L029878 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Hi Bob, Sure, you are welcome, not a hassle. Most code is similar a stone rolling through time, Over time the sharp edges get nicely shaped. Lot of public code is like that, it takes time and effort to evolve. Best Regards, Manu On Thu, Jul 30, 2020 at 11:44 PM Bob Blick wrote: > > Hi Manu, > I will give it a try. I guess I wasn't just too stupid not to be able to = make it work without changes. Thank you very much. > Bob > > ________________________________________ > From: piclist-bounces@mit.edu on behalf of Manu= Abraham > Sent: Thursday, July 30, 2020 10:49 AM > To: Microcontroller discussion list - Public. > Subject: Re: [PIC] Simple GCC question > > Hi Bob, > > Another look at the github code, I would do this: > > #define MODE .. > > #define EN_PIN LL_GPIO_PIN_0 > #define EN_PORT GPIOB > .. > and more > > Lcd_HandleTypeDef lcd; <-- make this global, > > int main(void) > { > > .. do whatever .. > > lcd.mode =3D MODE; > > lcd.en_pin =3D EN_PIN; > lcd.en_port =3D EN_PORT; > > lcd.rs_pin =3D rs_pin; > lcd.rs_port =3D rs_port; > > lcd.data_pin =3D pin; > lcd.data_port =3D port; > > Lcd_init(&lcd); > > .. do whatever .. > > } > > Lcd_init() happens to be public via lcd.h. > So, you do not need to clobber the library, > but just that you do not need to call Lcd_create() fn. > > Advantage, lower memory usage, lesser complexity. :-) > > Regards, > Manu > > On Thu, Jul 30, 2020 at 11:08 PM Bob Blick wrote: > > > > Hi Manu, > > > > Although the LCD will not normally be driven from interrupts, if there = is a lockup I would like it to leave an error code on the display, which wo= uld need to be done from an interrupt. > > > > I guess to make it global without errors I will need to hardcode the po= rts and pins so I get rid of the arrays that are handed to Lcd_create() > > > > Thanks, Bob > > > > ________________________________________ > > From: piclist-bounces@mit.edu on behalf of Ma= nu Abraham > > Sent: Thursday, July 30, 2020 9:55 AM > > To: Microcontroller discussion list - Public. > > Subject: Re: [PIC] Simple GCC question > > > > On Thu, Jul 30, 2020 at 9:57 PM Bob Blick wrote: > > > > > > I'm using a nice little HD44780 LCD library in an STM32 project, it w= orks great but I'm stuck with a variable scope problem that I can only seem= to make worse because GCC is a bit stricter than I want it to be at this p= oint. Sorry if the code example doesn't wordwrap properly. > > > > > > If, somewhere in main() I create an instance of the LCD like this: > > > Lcd_PortType ports[] =3D {LCD_D4_GPIO_Port, LCD_D5_GPIO_Port, LCD_D= 6_GPIO_Port, LCD_D7_GPIO_Port}; > > > Lcd_PinType pins[] =3D {LCD_D4_Pin, LCD_D5_Pin, LCD_D6_Pin, LCD_D7_= Pin}; > > > Lcd_HandleTypeDef lcd =3D Lcd_create(ports, pins, LCD_RS_GPIO_Port,= LCD_RS_Pin, LCD_EN_GPIO_Port, LCD_EN_Pin, LCD_4_BIT_MODE); > > > > > > > Why I dislike opaque datatypes... > > > > Instead of copying objects to Lcd_create(), a pointer could have been u= sed, > > storage could have been global, made static .. > > the variables appear to be for configuration purposes ? > > > > One way to do is make the lcd object global. > > > > Another way is to pass a lcd object pointer to whatever function you > > are calling, > > unless you need to access the lcd object from interrupt context. > > If you need access from interrupt context, the easier way is to have > > global storage. > > > > -- > > > > -- > http://www.piclist.com/techref/piclist PIC/SX FAQ & list archive > View/change your membership options at > http://mailman.mit.edu/mailman/listinfo/piclist --=20 http://www.piclist.com/techref/piclist PIC/SX FAQ & list archive View/change your membership options at http://mailman.mit.edu/mailman/listinfo/piclist .