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 10:59:08 -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 06UHng2k024359; Thu, 30 Jul 2020 13:49:52 -0400 Received: from outgoing-exchange-1.mit.edu (OUTGOING-EXCHANGE-1.MIT.EDU [18.9.28.15]) by PCH.mit.edu (8.14.7/8.12.8) with ESMTP id 06UHnfG8024356 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Thu, 30 Jul 2020 13:49:41 -0400 Received: from w92exedge3.exchange.mit.edu (W92EXEDGE3.EXCHANGE.MIT.EDU [18.7.73.15]) by outgoing-exchange-1.mit.edu (8.14.7/8.12.4) with ESMTP id 06UHm3wU017873 for ; Thu, 30 Jul 2020 13:48:18 -0400 Received: from oc11expo11.exchange.mit.edu (18.9.4.16) by w92exedge3.exchange.mit.edu (18.7.73.15) with Microsoft SMTP Server (TLS) id 15.0.1293.2; Thu, 30 Jul 2020 13:49:05 -0400 Received: from oc11exhyb7.exchange.mit.edu (18.9.1.112) by oc11expo11.exchange.mit.edu (18.9.4.16) with Microsoft SMTP Server (TLS) id 15.0.1365.1; Thu, 30 Jul 2020 13:49:29 -0400 Received: from NAM12-MW2-obe.outbound.protection.outlook.com (104.47.66.41) by oc11exhyb7.exchange.mit.edu (18.9.1.112) with Microsoft SMTP Server (TLS) id 15.0.1395.4 via Frontend Transport; Thu, 30 Jul 2020 13:49:28 -0400 Received: from DM6PR12CA0034.namprd12.prod.outlook.com (2603:10b6:5:1c0::47) by DM6PR01MB4748.prod.exchangelabs.com (2603:10b6:5:6f::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3216.24; Thu, 30 Jul 2020 17:49:27 +0000 Received: from DM3NAM03FT049.eop-NAM03.prod.protection.outlook.com (2603:10b6:5:1c0:cafe::ce) by DM6PR12CA0034.outlook.office365.com (2603:10b6:5:1c0::47) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3239.17 via Frontend Transport; Thu, 30 Jul 2020 17:49:27 +0000 Received: from mail-yb1-f174.google.com (209.85.219.174) by DM3NAM03FT049.mail.protection.outlook.com (10.152.83.125) 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 17:49:27 +0000 Received: by mail-yb1-f174.google.com with SMTP id 2so14862106ybr.13 for ; Thu, 30 Jul 2020 10:49:27 -0700 (PDT) From: Manu Abraham To: Microcontroller discussion list - Public. Sender: "piclist-bounces@mit.edu" Date: Thu, 30 Jul 2020 10:49:13 -0700 Subject: Re: [PIC] Simple GCC question Thread-Topic: [PIC] Simple GCC question Thread-Index: AdZmmx+wUZHKFjRiSuaLLlDFQhc6Sw== 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.174 as permitted sender) receiver=protection.outlook.com; client-ip=209.85.219.174; helo=mail-yb1-f174.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=L/PpoS8MyVzKLT/HujoKjYCwOX1jrK6P1kfBwVykXUA=; b=hfB336Fb0NEjRHPUN6sOA7fdp9kImbf3AIf5ZutJ3GKY3+Nsh2/ujgw9ZzdP+ckAs1 iHSG8MfjHZFpF3N+QC4sf9WrdZKf+ZrHO/pvb+W9QN96IlGFjrnfU1pV0L8KA62Az3rj t7hJ9q/tGR9Iv55LcsHPITA4D0bkXnO82tZUxtDXNXIZIi8dQp8cteoVkGVZE6iSWy1Y CTULKISZiQPJNn1SDltxrU70VSoPVtdi4fKimltkpDkWrpYJzw5hmFATmf+3QtNmlBWP t4ExNdSamBs6MkzXlM5XlzduChptX/1Z2rGR7wFgPlKUWaVyzmlzGyMucCBrkHQu5lAS WfPQ== authentication-results: spf=pass (sender IP is 209.85.219.174) 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:1fd5:: with SMTP id f204mr75417ybf.236.1596131366340; Thu, 30 Jul 2020 10:49:26 -0700 (PDT) x-topics: [PIC] x-mime-autoconverted: from quoted-printable to 8bit by PCH.mit.edu id 06UHnfG8024356 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 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 woul= d need to be done from an interrupt. > > I guess to make it global without errors I will need to hardcode the port= s 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 Manu= 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 wor= ks great but I'm stuck with a variable scope problem that I can only seem t= o make worse because GCC is a bit stricter than I want it to be at this poi= nt. 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_D6_= GPIO_Port, LCD_D7_GPIO_Port}; > > Lcd_PinType pins[] =3D {LCD_D4_Pin, LCD_D5_Pin, LCD_D6_Pin, LCD_D7_Pi= n}; > > Lcd_HandleTypeDef lcd =3D Lcd_create(ports, pins, LCD_RS_GPIO_Port, L= CD_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 use= d, > 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 .